Last active
December 3, 2019 03:56
-
-
Save Wonder2210/9f5662b1fb0dee8b8f746e3c1e5ccb55 to your computer and use it in GitHub Desktop.
Basic initialization store for React + Redux projects using connected-react-router and redux thunk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import | |
React,{Component | |
}from 'react'; | |
import {Route,Switch} from 'react-router'; | |
import {Link} from 'react-router-dom'; | |
import {ConnectedRouter} from 'connected-react-router'; | |
import {history} from './store'; | |
import {Provider} from 'react-redux'; | |
import {configureStore} from './store'; | |
const store = configureStore(); | |
const App = ({}) => ( | |
( | |
<Provider store={store}> | |
<ConnectedRouter history={history}> | |
<div > | |
<Route exact path="/" component={()=>(<h1>Here we are</h1>)}/> | |
</div> | |
</ConnectedRouter> | |
</Provider> | |
); | |
); | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {combineReducers} from 'redux'; | |
import {connectRouter} from 'connected-react-router'; | |
import getUsers from './user';//export your reducer | |
const rootReducer=history=>combineReducers({router:connectRouter(history),getUsers}) | |
export default rootReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createStore,applyMiddleware,compose} from 'redux'; | |
import { createBrowserHistory} from 'history'; | |
import { routerMiddleware} from 'connected-react-router'; | |
import thunk from 'redux-thunk'; | |
import rootReducer from './reducers'; | |
export const history = createBrowserHistory(); | |
export const configureStore=(preloadedState)=>{ | |
const store= createStore(rootReducer(history),compose( | |
applyMiddleware(thunk,routerMiddleware(history)) | |
) | |
); | |
return store; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment