-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathapp-state-hoc.jsx
33 lines (29 loc) · 1.04 KB
/
app-state-hoc.jsx
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
import React from 'react';
import {Provider} from 'react-redux';
import {createStore, applyMiddleware, compose} from 'redux';
import throttle from 'redux-throttle';
import {intlInitialState, IntlProvider} from '../reducers/intl.js';
import reducer from '../reducers/gui';
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const enhancer = composeEnhancers(
applyMiddleware(
throttle(300, {leading: true, trailing: true})
)
);
const store = createStore(reducer, intlInitialState, enhancer);
/*
* Higher Order Component to provide redux state
* @param {React.Component} WrappedComponent - component to provide state for
* @returns {React.Component} component with redux and intl state provided
*/
const AppStateHOC = function (WrappedComponent) {
const AppStateWrapper = ({...props}) => (
<Provider store={store}>
<IntlProvider>
<WrappedComponent {...props} />
</IntlProvider>
</Provider>
);
return AppStateWrapper;
};
export default AppStateHOC;