'how to use it correctly useSelector()

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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chad S.