You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Creates a persisted reducer that wraps Redux Toolkit's `createReducer`.
21
-
* This function enhances a standard reducer with automatic state persistence,
22
-
* saving its state to storage and rehydrating it on app startup.
23
21
*
24
-
* This function must be used with a store configured by `configurePersistedStore`.
22
+
* This function enhances a standard reducer with automatic state persistence,
23
+
* saving its state to storage and rehydrating it when the application starts.
24
+
* It must be used with a store configured by `configurePersistedStore`.
25
25
*
26
-
* @param reducerName - A unique string name for the reducer. This name serves as the key in both the root state and the storage.
27
-
* @param initialState - The initial state for the reducer.
28
-
* @param mapOrBuilderCallback - A callback that receives a `builder` object to define case reducers, similar to the original `createReducer`.
29
-
* @param nestedPath - An optional dot-separated string path indicating where the reducer's state is located within the root state. If not provided, `reducerName` is used.
30
26
* @public
27
+
* @param reducerName - A unique name for the reducer. This name is used as the key
28
+
* in both the root state and the underlying storage.
29
+
* @param initialState - The initial state for the reducer, same as in `createReducer`.
30
+
* @param mapOrBuilderCallback - A callback that receives a `builder` object to define
31
+
* case reducers. This builder is wrapped to automatically track state changes for persistence.
32
+
* @param persistenceOptions - Optional configuration for customizing persistence behavior.
33
+
* @returns A reducer function enhanced with persistence capabilities.
34
+
*
35
+
* @example
36
+
* ```typescript
37
+
* const counterReducer = createPersistedReducer(
38
+
* 'counter',
39
+
* { value: 0 },
40
+
* (builder) => {
41
+
* builder.addCase(increment, (state) => {
42
+
* state.value++;
43
+
* });
44
+
* },
45
+
* {
46
+
* // Optional: Specify a different path in the root state.
0 commit comments