简体   繁体   中英

Usecase of redux over normal state mechanism in react native

I am developing react native application. I came across redux for state management of the application.

Suppose I have welcome tour in my application which should be one time view activity. I can save this in normal state and check in my component.

This can be doable using redux too, then how redux is different than normal state. Any use case ?

Redux in React Native is no different than Redux in a normal React application so all advice on Redux vs local state apply.

Quoting Redux docs:

Using local component state is fine. As a developer, it is your job to determine what kinds of state make up your application, and where each piece of state should live. Find a balance that works for you, and go with it.

Some common rules of thumb for determining what kind of data should be put into Redux:

  • Do other parts of the application care about this data?
  • Do you need to be able to create further derived data based on this original data?
  • Is the same data being used to drive multiple components?
  • Is there value to you in being able to restore this state to a given point in time (ie, time travel debugging)?
  • Do you want to cache the data (ie, use what's in state if it's already there instead of re-requesting it)?

Quoting Dan Abramov, the author of Redux:

If you're just learning React, don't make Redux your first choice. Instead learn to think in React. Come back to Redux if you find a real need for it, or if you want to try something new. But approach it with caution, just like you do with any highly opinionated tool.

and my favourite:

The rule of thumb is: do whatever is less awkward.

Sources:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM