mirror of
https://github.com/strapi/strapi.git
synced 2025-08-31 20:33:03 +00:00
Created useInjectReducer and useeInjectSaga hooks
This commit is contained in:
parent
cc1dd40d82
commit
c0a01f1e5a
@ -1,3 +1,8 @@
|
||||
# getstarted
|
||||
|
||||
A quick description of getstarted.
|
||||
|
||||
|
||||
Start the app with mongo
|
||||
|
||||
`DB=mongo yarn develop`
|
||||
|
@ -1,5 +1,7 @@
|
||||
const injectReducer = require('./utils/injectReducer').default;
|
||||
const useInjectReducer = require('./utils/injectReducer').useInjectReducer;
|
||||
const injectSaga = require('./utils/injectSaga').default;
|
||||
const useInjectSaga = require('./utils/injectSaga').useInjectSaga;
|
||||
const { languages } = require('./i18n');
|
||||
|
||||
window.strapi = Object.assign(window.strapi || {}, {
|
||||
@ -13,6 +15,8 @@ window.strapi = Object.assign(window.strapi || {}, {
|
||||
'en',
|
||||
injectReducer,
|
||||
injectSaga,
|
||||
useInjectReducer,
|
||||
useInjectSaga,
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
@ -34,3 +34,14 @@ export default ({ key, reducer, pluginId }) => WrappedComponent => {
|
||||
|
||||
return hoistNonReactStatics(ReducerInjector, WrappedComponent);
|
||||
};
|
||||
|
||||
const useInjectReducer = ({ key, reducer, pluginId }) => {
|
||||
const context = React.useContext(ReactReduxContext);
|
||||
const reducerName = pluginId ? `${pluginId}_${key}` : key;
|
||||
|
||||
React.useEffect(() => {
|
||||
getInjectors(context.store).injectReducer(reducerName, reducer);
|
||||
}, []);
|
||||
};
|
||||
|
||||
export { useInjectReducer };
|
||||
|
@ -49,3 +49,19 @@ export default ({ key, saga, mode, pluginId }) => WrappedComponent => {
|
||||
|
||||
return hoistNonReactStatics(InjectSaga, WrappedComponent);
|
||||
};
|
||||
|
||||
const useInjectSaga = ({ key, saga, mode, pluginId }) => {
|
||||
const context = React.useContext(ReactReduxContext);
|
||||
const sagaName = pluginId ? `${pluginId}_${key}` : key;
|
||||
|
||||
React.useEffect(() => {
|
||||
const injectors = getInjectors(context.store);
|
||||
injectors.injectSaga(sagaName, { saga, mode });
|
||||
|
||||
return () => {
|
||||
injectors.ejectSaga(sagaName);
|
||||
};
|
||||
}, []);
|
||||
};
|
||||
|
||||
export { useInjectSaga };
|
||||
|
@ -10,6 +10,8 @@ async function createPluginsJs(plugins, dest) {
|
||||
const content = `
|
||||
const injectReducer = require('./utils/injectReducer').default;
|
||||
const injectSaga = require('./utils/injectSaga').default;
|
||||
const useInjectReducer = require('./utils/injectReducer').useInjectReducer;
|
||||
const useInjectSaga = require('./utils/injectSaga').useInjectSaga;
|
||||
const { languages } = require('./i18n');
|
||||
|
||||
window.strapi = Object.assign(window.strapi || {}, {
|
||||
@ -23,6 +25,8 @@ async function createPluginsJs(plugins, dest) {
|
||||
'en',
|
||||
injectReducer,
|
||||
injectSaga,
|
||||
useInjectReducer,
|
||||
useInjectSaga,
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user