Answer the question
In order to leave comments, you need to log in
React + redux which state structure to choose for form and component?
I am doing the first project on react and the question arose of how to do it right, because different approaches are used everywhere.
There are pages (part of the state is the same for everyone):
Authorization
Registration
Password recovery
For example, for the registration page, I made such a global state
const initialState = {
isSuccess: false,
isLoading: false,
isError: false,
errorMessage: ""
};
export const signupRequest = formData => async dispatch => {
try {
dispatch(signupRequestProcess());
const data = await api("post", "auth/signup", formData);
dispatch(signupSuccess(data));
} catch (error) {
dispatch(signupRequestError(error));
}
};
Answer the question
In order to leave comments, you need to log in
That's why different approaches are used everywhere because there is no one "correct" one.
Write as you like, and over time, in each case, you will understand how to do better.
You can, like you, you can put a state in the component, change the flag from true to false is not so much logic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question