0

Currently, each of my components' state is stored in useState hooks. I want to be able to persist the states of all my components so that when a user navigates back to a previous page, etc., they will pick up where they left off.

Is this too costly?

  • Does each new object / state have an associated overhead in the form of computational and/or memory cost? Yes. Is that overhead completely negligible compared to the clarity provided by separation of concerns in your application's source code? Absolutely. ["Make it work, make it right, make it fast"](https://wiki.c2.com/?MakeItWorkMakeItRightMakeItFast) – jsejcksn Jul 13 '22 at 03:09

1 Answers1

1

With Redux you don't have multiple stores, you have a single store that maintains a global redux state.

You use that state within your component be using a selector, as such:

const bar = useSelector(state => state.foo.bar)

Your component will only rerender when the individual sub-state you select changes.

Redux is performant, and you can have a lot of state within it without causing any performance issues. However, you generally don't want to offload everything to Redux, because it has development overhead, and because some state is more logically scoped to an individual component.

tl;dr; it's not costly to have a lot of state in your Redux store as opposed to using useState

Nathan
  • 73,987
  • 14
  • 40
  • 69