How to remove a slice / reducer in a redux store?

Viewed 100

In the register component of my APP, the state is stored in a redux slice. After the user registers, this component will never be rendered again and thus the memory in its redux slice should be freed up for performance.

How can this be done?

3 Answers

The performance gain from freeing up a tiny bit of memory is negligible if even measurable, don't bother.

Can I dynamically add / remove slice of the state ?

Yes you can remove / add dynamically a slice of the state with redux, this is usually done for code splitting reasons

How to do it ?

You can follow this steps to achieve it: https://redux.js.org/usage/code-splitting

Note

I agree with @timotgl note, based on what you have in this slice this is negligible

Redux is generally used for global state. What you are describing is local state, and should probably be moved out of redux, and into local component state. You could keep your reducer, actions, and selectors, and just refactor them into a call to React.useReducer instead of redux.

Related