DEV Community

Discussion on: Senior front end dev here, ask me anything!

Collapse
 
parmeshshiroya profile image
parmesh

In react where should i use redux.

Should i store all states in redux?
Should i call all apis in redux?
What data should i put in redux?

currently in my company we do all type of api calling in redux. Sometime it cause issue like because it's UI is connected with store. it shows previous data first and after few sec. it shows new data.
Do you have any repo where i can see good coding structure?

Collapse
 
kendalmintcode profile image
Rob Kendal {{☕}}

Hey Parmesh,

I have a good article on this using data handlers with Redux which might be a good read for you.

But, to answer your questions, in order:

  1. Use redux to manage (store, retrieve and edit) only the parts of state that don't make sense to keep locally to the component. For example, if you have a number of components that depend on the loading state of an API call to display different UI elements: this belongs in global state. Similar if you need to share parts of common data across different, unrelated components.

  2. No, not everything state-related should live in redux global state. See answer one, but mainly if you have something that's local (for example, a toggle state of a button) then keep that in the component and don't involve redux

  3. I'm not entirely sure I understand that one, but I would say 'no'. You might call redux actions based on the outcome of an API call, but don't call API's using redux. The redux pattern should be used to update state and that's it.

  4. I think this is answered in the previous answers :)

  5. Yep, check out the article link in the first part.