Ad

React Redux Architecture Suggestion

- 1 answer

Confussed between which is best to use react class state or redux state for onChange operation of the form elements.

I have a form for entering,displaying user details, I am using react-redux architecture, on-change or on-load I am populating the data from the api to the respective text boxes using the class state/localstate, when the user inputs any data I am using the setState . I came to know that there is another way to do it by dispatching an action and storing the data in the redux state instead of local state,so please suggest me which is the standard way to do it, as some prefer not to use local state.

Ad

Answer

It is generaly as @sebastienbarbier suggested. If you don't need to share your state between different parts of application, the react state is usually better.

I am using the react state for handling onChange for controlled components (typically text inputs). And a redux action is created (and store updated) once when I submit a form.

Ad
source: stackoverflow.com
Ad