redux-persist
redux-persist copied to clipboard
Ineffective re-saving of the same data
Lets say we have usersReducer that stores only current user:
export type UsersState = {
currentUserId: string;
profiles: Record<string, UserProfile>;
};
export const usersReducer = persistReducer({
key: 'users',
throttle: 5000,
whitelist: ['currentUserId', 'profiles'],
transforms: [
createTransform(
(subState: UsersState['profiles'], _, state: UsersState) => {
const currentUserId = state.currentUserId;
return currentUserId ? {
[currentUserId]: subState[currentUserId],
} : {};
},
null,
{ whitelist: ['profiles'] },
),
],
}, reducer);
So it should call Storage.set only when current user changes. But no, it calls It every time when profiles state changes.
Is there a way to compare prev and new state before saving? Similar to mapStateToProps re-rendering.