Answer the question
In order to leave comments, you need to log in
How to properly set initialState in redux?
For example, in my initialState - there are a couple of fields, this is the user field - where user data is stored during authorization, and the auth field - a kind of additional flag - which becomes true if the user is authorized
const initialState = {
auth: false,
user: null
}
const initialState = () => {
let state = {}
....//проверка на auth
....//если авторизонван - то state.auth = true и state.user = response.user к примеру
return state;
}
Answer the question
In order to leave comments, you need to log in
You can do this in the code where you create the initialState object. Where is it created?
Although the presence of authorization is unlikely to be checked synchronously. Even if there is a cookie or an entry in the localStorage, it is not a fact that it is valid, so you need to make a request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question