@@ -119,26 +119,18 @@ Whichever option you choose, you must use `configurePersistedStore` and provide
119119```
120120// app/store.ts
121121import { configurePersistedStore } from 'rtk-persist';
122- // Import your slice reducer (Option 1)
123- import counterSliceReducer from '../features/counter/counterSlice';
124- // OR import your persisted reducer (Option 2)
122+ import { counterSlice } from '../features/counter/counterSlice';
125123import { reducer as counterReducer } from '../features/counter/counterReducer';
126124
127125// For web, use localStorage or sessionStorage
128126const storage = localStorage;
129127
130- // For React Native, you would use:
131- // import AsyncStorage from '@react-native-async-storage/async-storage';
132- // const storage = AsyncStorage;
133-
134128export const store = configurePersistedStore(
135129 {
136130 reducer: {
137- // For Option 1 (createPersistedSlice)
138- counter: counterSliceReducer,
139-
140- // For Option 2 (createPersistedReducer)
141- // counter: counterReducer,
131+ // IMPORTANT: The key must match the slice's `reducerPath` (which defaults to the slice's name) or the reducer's `reducerName`.
132+ [counterSlice.reducerPath]: counterSlice.reducer,
133+ // [counterReducer.reducerName]: counterReducer,
142134 },
143135 },
144136 'applicationId',
@@ -158,41 +150,58 @@ export type AppDispatch = typeof store.dispatch;
158150
159151## 🛠️ API
160152
161- ### ` createPersistedSlice(sliceOptions) `
153+ < div class = " api-section " >
162154
155+ ### ` createPersistedSlice `
163156A wrapper around RTK's ` createSlice ` .
164157
158+ <h4 >Arguments</h4 >
159+
165160* ** ` sliceOptions ` ** : The standard ` CreateSliceOptions ` object.
166161
167- ### ` createPersistedReducer(name, initialState, builderCallback) `
162+ <h4 >Returns</h4 >
163+
164+ * A standard ` Slice ` object from Redux Toolkit. You can access its name via ` slice.name ` or ` slice.reducerPath ` .
168165
166+ ---
167+
168+ ### ` createPersistedReducer `
169169A wrapper around RTK's ` createReducer ` .
170170
171- * ** ` name ` ** : A unique string to identify this reducer in storage.
171+ < h4 >Arguments</ h4 >
172172
173+ * ** ` name ` ** : A unique string to identify this reducer in storage.
173174* ** ` initialState ` ** : The initial state for the reducer.
174-
175175* ** ` builderCallback ` ** : A callback that receives a ` builder ` object to define case reducers.
176176
177- ### ` configurePersistedStore(storeOptions, applicationId, storageHandler, persistenceOptions?) `
177+ < h4 >Returns</ h4 >
178178
179+ * A standard ` Reducer ` function, enhanced with the following property:
180+ * ** ` reducerName ` ** : A property that holds the provided ` name ` .
181+
182+ ---
183+
184+ ### ` configurePersistedStore `
179185A wrapper around RTK's ` configureStore ` .
180186
181- * ** ` storeOptions ` ** : The standard ` ConfigureStoreOptions ` object.
187+ < h4 >Arguments</ h4 >
182188
189+ * ** ` storeOptions ` ** : The standard ` ConfigureStoreOptions ` object.
183190* ** ` applicationId ` ** : A unique string that identifies the application.
184-
185191* ** ` storageHandler ` ** : A storage object that implements ` getItem ` , ` setItem ` , and ` removeItem ` .
186-
187192* ** ` persistenceOptions ` ** (optional): An object to control the persistence behavior:
193+ * ` rehydrationTimeout ` (optional, ` number ` ): Max time in ms to wait for rehydration. Defaults to ` 5000 ` .
194+ * ` onRehydrationStart ` (optional, ` () => void ` ): Callback invoked when rehydration begins.
195+ * ` onRehydrationSuccess ` (optional, ` () => void ` ): Callback invoked on successful rehydration.
196+ * ` onRehydrationError ` (optional, ` (error: unknown) => void ` ): Callback invoked on rehydration error.
188197
189- * ` rehydrationTimeout ` (optional, ` number ` ): The maximum time in milliseconds to wait for rehydration to complete before timing out. Defaults to ` 5000 ` .
190-
191- * ` onRehydrationStart ` (optional, ` () => void ` ): A callback invoked when the rehydration process begins.
198+ <h4 >Returns</h4 >
192199
193- * ` onRehydrationSuccess ` (optional, ` () => void ` ): A callback invoked when the rehydration process completes successfully.
200+ * A ` PersistedStore ` object, which is a standard Redux store enhanced with the following methods:
201+ * ** ` rehydrate() ` ** : A function to manually trigger rehydration from storage.
202+ * ** ` clearPersistedState() ` ** : A function that clears all persisted data for the application from storage.
194203
195- * ` onRehydrationError ` (optional, ` (error: unknown) => void ` ): A callback invoked if an error occurs during rehydration.
204+ </ div >
196205
197206<br />
198207
0 commit comments