Is there any way to console log the whole state tree once that reducer updates new state?

Viewed 5633

I am new to react native. I would like to know the current state tree once a reducer function has been executed. I want to know the state tree latest value.

I have set the logic in dumb component that if loggedIn state is true, render page 2, if it is false, render page 1.

Is dumb component not knowing the update, or is that is not the right way to arrange the flow?

My action is when i init the store, i dispatch an action to check if there's access token in user local storage. if it is exists, update the state.. But somehow it seems like the state does not updated.

EDITED:

This is my reducer

const initialState = {
    token: null,
    username: null,
    loggedIn: false
}

export const reducer = (state = initialState, action) => {

    switch (action.type) {
        // Reducer does not handle API type of actions
        case types.STORE_TOKEN:
            AsyncStorage.setItem(localStorage.ACCESS_TOKEN, JSON.stringify(action.payload.token))
            return {
                token: action.payload.token,
                username : action.payload.username,
                loggedIn: true
            }
        case types.GET_TOKEN:
            AsyncStorage.getItem(localStorage.ACCESS_TOKEN).then((storage) =>{
                if(!storage){ return state }
                return {
                    token: storage,
                    loggedIn: true
                }
            })
        default:
            return state
    }
}
2 Answers
Related