Comments (9)
redux-persist
has a piece of documentation that implies one needs to call persistReducer
every time they call replaceReducer
. Since we call replaceReducer
internally within this library, it's not possible to use redux-persist
currently.
We could probably add a mechanism for allowing this. Maybe some kind of hook onReplaceReducer
or something. I'll try to find some time to look into this.
from redux-injectors.
@AleXzpm I thought about this some more and I don't think this requires any changes in redux-injectors
. Something like this should work:
const createReducer = (injectedReducers) => {
const combinedReducer = combineReducers(injectedReducers);
const persistedReducer = persistReducer(persistConfig, combinedReducer);
return persistedReducer;
}
The key is to move the persistReducer
call into createReducer
. Lmk if that doesn't work for you.
from redux-injectors.
It works for me thank you @BenLorantfy 🙏
from redux-injectors.
@AleXzpm hi, did you find the solution?
from redux-injectors.
@BenLorantfy thank you, and could you please investigate how we can use immer with your library?
from redux-injectors.
@siarheipashkevich no I did not, other then giving up on Injectors. Hopefully @BenLorantfy can create some hook for this.
from redux-injectors.
@siarheipashkevich immer should work fine with this library... were you running into any issues?
from redux-injectors.
@BenLorantfy @Pixel-Jack
Should that last solution work all the same if its dynamic injected reducers like in react-boilerplate-cra-template
import { combineReducers } from '@reduxjs/toolkit';
import { InjectedReducersType } from 'utils/types/injector-typings';
/**
* Merges the main reducer with the router state and dynamically injected reducers
*/
export function createReducer(injectedReducers: InjectedReducersType = {}) {
// Initially we don't have any injectedReducers, so returning identity function to avoid the error
if (Object.keys(injectedReducers).length === 0) {
return state => state;
} else {
return combineReducers({
...injectedReducers,
});
}
}
as
export function createReducer(injectedReducers: InjectedReducersType = {}) {
// Initially we don't have any injectedReducers, so returning identity function to avoid the error
if (Object.keys(injectedReducers).length === 0) {
return state => state;
} else {
const combinedReducers = combineReducers({ ...injectedReducers, });
const persistedReducer = persistReducer(persistConfig, combinedReducer);
return persistedReducer;
}
}
and then in configureStore leave it as
const store = configureStore({
reducer: createReducer(),
...etc
});
from redux-injectors.
EDIT, nope, need to refactor saga reducer wiring, store config, to include reducers/sagas statically for persisting and rehydrating for react-boilerplate-cra-template
from redux-injectors.
Related Issues (20)
- Typescript support? HOT 1
- Typescript error: implicit "any" HOT 1
- Change in the order of Hooks when injecting a reducer, calling it, and selector-ing it withing a single component HOT 2
- Feature Request: Ability to change the saga registered on a component using Hooks HOT 4
- React 16.13 throws a warning when "nesting" useInjectReducer calls HOT 54
- Feature Request: useInjectSagas ie useInjectSaga for multiple sagas HOT 5
- How do I clear state on logout HOT 2
- update to react 17 HOT 1
- Typing issues with latest @reduxjs/toolkit HOT 1
- Unmet peer dependencies with React 18 HOT 8
- incorrect typing for function `createManager` ? HOT 2
- Can I integrate to Next.Js? HOT 2
- Not able to get the store value HOT 2
- useInjectReducer clears the state HOT 2
- installing redux-injectors without --force or --legacy-peer-deps HOT 2
- [React Testing Library] Integration tests with preloadedState
- Feature request: reducer ejection HOT 1
- Unmet peer dependencies with Redux 8 HOT 5
- How to create reducer with Immer ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-injectors.