-
Notifications
You must be signed in to change notification settings - Fork 866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Redux v5 and RTK v2 #1459
Comments
I also updated to RTK v2 and I'm not having any type-issues. Where did you encounter type errors? |
A more detailed explanation of the change for context: Prior to Redux v5, the handling for For a long time this was handled by a special In v5, we took the opportunity to rethink how type Reducer<S, A extends Action = Action, P = S> = (state: S | P | undefined, action: A) => S This means that the result of However when you pass it to Users can fix this themselves by adding an overload that knows to preserve import type { Action, Reducer } from "redux";
import type { PersistConfig, PersistState } from "redux-persist";
declare module "redux-persist" {
export function persistReducer<S, A extends Action = Action, P = S>(
config: PersistConfig<S>,
baseReducer: Reducer<S, A, P>,
): Reducer<
S & { _persist: PersistState },
A,
P & { _persist?: PersistState }
>;
} But it'd obviously be nicer if the library could be updated to handle this itself 🙂 |
You probably will also have to override the dependency. You can do so with npm overrides: in your {
// ...
"dependencies": {
"@reduxjs/toolkit": "^2.0.1",
"react-redux": "^9.0.2",
"redux-persist": "^6.0.0"
},
"overrides": {
"redux-persist": {
"redux": "^5.0.0"
}
}
} |
I guess |
@xsjcTony Good point. One of our users had problems with that, but I didn't notice it was using |
Update is pretty important. I experience issue that |
Same issue here: |
could either of you put together a reproduction of the issue? |
Here is store setup example that I have in app. Also react-redux to reproduce requires v9+. I downgraded to v8 to fix the issue store.tsximport AsyncStorage from '@react-native-async-storage/async-storage'
import { configureStore, ThunkAction } from '@reduxjs/toolkit'
import { shallowEqual, TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import { persistStore, persistReducer, FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER } from 'redux-persist'
import { Action } from './app/actions'
import { middleware } from './middleware'
import AppReducers from './index'
const persistedReducer = persistReducer(
{
key: 'root',
storage: AsyncStorage,
version: 2,
},
AppReducers,
)
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) => {
return getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}).concat(middleware)
},
})
// const sagaMiddleware = createSagaMiddleware()
export const persistor = persistStore(store)
// sagaMiddleware.run(saga)
export default {
store,
persistor,
}
export const useAppDispatch = () => useDispatch<ReduxDispatch>()
export const useAppSelector: TypedUseSelectorHook<ReduxState> = (selector) => useSelector(selector, shallowEqual)
/* Types */
export type ReduxStore = typeof store
export type ReduxState = ReturnType<typeof AppReducers>
export type ReduxDispatch = typeof store.dispatch
export type ReduxThunkAction<ReturnType = void> = ThunkAction<ReturnType, ReduxState, unknown, Action> slice.tsimport { createSlice, PayloadAction } from '@reduxjs/toolkit'
interface State {
deviceLocale: string
appLocale: string
}
const initialState: State = {
deviceLocale: '',
appLocale: '',
}
const slice = createSlice({
name: 'SYSTEM',
initialState,
reducers: {
setLocale(state, action: PayloadAction<Pick<State, 'appLocale' | 'deviceLocale'>>) {
const { appLocale, deviceLocale } = action.payload
state.appLocale = appLocale
state.deviceLocale = deviceLocale
},
},
})
export const { reducer, actions } = slice
export default reducer |
Functionality seems working fine, but types may need to be adjusted.
🙏
The text was updated successfully, but these errors were encountered: