-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap-with-provider.js
34 lines (24 loc) · 1.04 KB
/
wrap-with-provider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React from "react"
import { Provider } from "react-redux"
// import createStore from "./src/store/createStore"
import { createStore as reduxCreateStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk'
import reducer from './src/store/reducer'
// import rootReducer from '.';
const windowGlobal = typeof window !== 'undefined' && window;
const devtools =
process.env.NODE_ENV === 'development' && windowGlobal.devToolsExtension
? window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__()
: f => f;
// const createStore = () => reduxCreateStore(reducer, applyMiddleware(thunk));
const createStore = () => reduxCreateStore(reducer, compose(applyMiddleware(thunk), devtools));
// export default ({ element }) => (
// <Provider store={createStore()}>{element}</Provider>
// );
// eslint-disable-next-line react/display-name,react/prop-types
function wrapWithProvider({ element }) {
const store = createStore()
return <Provider store={store}>{element}</Provider>
}
export default wrapWithProvider