Home > database >  Best Way to re-render a unique state
Best Way to re-render a unique state

Time:02-23

My application depends mainly on one async method: my get-all-images function. And my app have like some components that will affect this method (ex: there's a search button on header, a add component, and a delete component). And I want to know what's the best way to make this function run again. ContextAPI?

This a is schetch of my app: enter image description here

CodePudding user response:

I think if the app is simple, it would be faster to do with useContext React Hook. You just put your state and setState in there, and then, get them in whatever component you need. But when your application gets bigger, it's getting hard to track the state and where it is updating. For that reason, there is Redux.

CodePudding user response:

Usually when you have this scenario, a common approach is using what you said, a React ContextAPI, with this you can correlate the components into the main state aid avoiding multiple re-renders with passing props.

Another approach, since your project need to have this "brain state" is to use solutions like recoil , redux or mobx to create a flux architecture inside of it and manage better how the components handle each state update.

  • Related