Home > Net >  how to use it correctly useSelector()
how to use it correctly useSelector()

Time:04-01

1 common useSelector() for the entire application, and transmit data via props?

Or a local useSelector() wherever data from the store is needed?


and why exactly so? I want to figure it out once and for all


Let's say I have 15 pages, and 60 components

Some say that you need to use it only 1 time, others that use wherever you need data from the store, and do not transfer anything through props.

soo.. I'm confused

CodePudding user response:

The correct answer is the second one.

a local useSelector() wherever data from the store is needed

If you had one selector at the top that gets the data and passes it down you avoid any/all of the benefits of redux. By selecting only the state you need, in each component that needs the state, your application is more efficient because only the components selecting state values that have been changed will be re-rendered.

  • Related