Repository URL to install this package:
|
Version:
5.0.0-rc.11 ▾
|
'use strict';
var index$3 = require('../../../prop-types/index.js');
var index$4 = require('../../../react/index.js');
var Context = require('./Context.js');
var Subscription = require('../utils/Subscription.js');
function Provider(_ref) {
var store = _ref.store,
context = _ref.context,
children = _ref.children;
var contextValue = index$4.default.useMemo(function () {
var subscription = new Subscription(store);
subscription.onStateChange = subscription.notifyNestedSubs;
return {
store: store,
subscription: subscription
};
}, [store]);
var previousState = index$4.default.useMemo(function () {
return store.getState();
}, [store]);
index$4.default.useEffect(function () {
var subscription = contextValue.subscription;
subscription.trySubscribe();
if (previousState !== store.getState()) {
subscription.notifyNestedSubs();
}
return function () {
subscription.tryUnsubscribe();
subscription.onStateChange = null;
};
}, [contextValue, previousState]);
var Context$1 = context || Context.ReactReduxContext;
return index$4.default.createElement(Context$1.Provider, {
value: contextValue
}, children);
}
if (process.env.NODE_ENV !== 'production') {
Provider.propTypes = {
store: index$3.default.shape({
subscribe: index$3.default.func.isRequired,
dispatch: index$3.default.func.isRequired,
getState: index$3.default.func.isRequired
}),
context: index$3.default.object,
children: index$3.default.any
};
}
module.exports = Provider;
//# sourceMappingURL=Provider.js.map