Home > other >  React Hook Concept Also Redux
React Hook Concept Also Redux

Time:01-05

  1. can I use Use state instead of redux?

  2. Can I Manage all the state by use state ?

CodePudding user response:

This question has a long and complicated answer, but I would suggest the first port of call would be reading up on the redux docs about how you might want to organise the state within your application.

TL;DR, it entirely depends on your situation, take a look here

CodePudding user response:

Both are valid, but both have cases where they are better to be used, for example if you have a state you want to manage one level below, and is not used by other components on different hierarchy, then passing the state and it's handler as a prop is the better solution.

But some cases are more complex and require a lot of passing down of a prop through the components until it reaches the child that actually uses it, and. the parents of that child do nothing but pass it down, that is a smell of bad code.

Here it is beneficial to have it in a global state where the child can access it directly, without needed all of its predecessors to pass it down as a prop (also known as prop-drilling). Another case where this is useful is when multiple components need to access the same state, in different part of the system. It would be much cleaner to have it stored in a global state available for every component that requires it.

TL;DR, depending on your case, one solution is better than the other. Assess your situation case-by-case.

  •  Tags:  
  • Related