Skip to content

Instantly share code, notes, and snippets.

@alfian0
Created March 2, 2017 09:42
Show Gist options
  • Select an option

  • Save alfian0/8fc92c930990033e5c0da34da0fe3c6d to your computer and use it in GitHub Desktop.

Select an option

Save alfian0/8fc92c930990033e5c0da34da0fe3c6d to your computer and use it in GitHub Desktop.
[Redux] React Native - Create Store
import React from 'react';
import {
AppRegistry,
} from 'react-native';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createLogger from 'redux-logger';
import reducer from './app/reducers';
import AppContainer from './app/containers/AppContainer';
import callAPIMiddleware from './app/lib/callAPIMiddleware';
const loggerMiddleware = createLogger({ predicate: (getState, action) => __DEV__ });
function configureStore(initialState) {
const enhancer = compose(
applyMiddleware(
thunkMiddleware,
loggerMiddleware,
callAPIMiddleware
),
);
return createStore(reducer, initialState, enhancer);
}
const store = configureStore({});
const App = () => (
<Provider store={store}>
<AppContainer />
</Provider>
);
AppRegistry.registerComponent('MyApp', () => App);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment