Home > Mobile >  how to use Redux instead for useSate or how to store data using Redux
how to use Redux instead for useSate or how to store data using Redux

Time:04-26

const[datas,setdatas]=useState("")

i have been using useState for storing variable and while finishing the last task my higher official told me to use Redux to store change and perform action . i read it in blog youtube videos but I can't quite get to know the necessary about redux. can someone suggest me a easy example or solution for me?

Thanking you in advance.

CodePudding user response:

If you have a bunch of nested components in you app, you have to send props every time to the new nested component. Then you feel like you want your states to be managed globally. Otherwise you probably have to type same props again and again.

This is why Redux and other state managing modules are needed. They put your state in a global storage and you can get that state in other component with props drilling. You only need to access global storage to get necessary state.

If your app has few components, redux or other state managing modules won't be necessary.

CodePudding user response:

Redux provides a easy way to pass data through the component tree without having to pass props down manually at every level, and you should only use it for global states.

I think you can keep using useState for local states.

enter image description here

  • Related