Last active
May 23, 2021 11:38
-
-
Save azamatsmith/ab814c869e81dc01b07782be0493ebcd to your computer and use it in GitHub Desktop.
Adding Redux to Gatsby - with devtools and redux-thunk
This file contains hidden or 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 from 'react'; | |
import { Router } from 'react-router-dom'; | |
import { Provider } from 'react-redux'; | |
import { applyMiddleware, compose, createStore } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import rootReducer from './src/reducers'; | |
const loadDevTools = () => | |
process.env.NODE_ENV === 'development' && window.devToolsExtension | |
? window.__REDUX_DEVTOOLS_EXTENSION__ && | |
window.__REDUX_DEVTOOLS_EXTENSION__() | |
: f => f; | |
const store = createStore( | |
rootReducer, | |
compose(applyMiddleware(thunk), loadDevTools()) | |
); | |
exports.replaceRouterComponent = ({ history }) => { | |
const ConnectedRouterWrapper = ({ children }) => ( | |
<Provider store={store}> | |
<Router history={history}>{children}</Router> | |
</Provider> | |
); | |
return ConnectedRouterWrapper; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment