Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
useSelector not updating after dispatching an action React Redux

I know there are already a couple of questions similar to this, but none of the solutions provided are working for me. I am dispatching an action in my React Native component, but when I try to access the state afterwards with useSelector, it is still just the previous state, not the updated one.

My component:

const userSettings = useSelector((state: any) => state.user.settings);

const loadUserSettings = async () => {
    await dispatch(userActions.fetchUserSettings());
}

const checkUserEnabled = async () => {
    await loadUserSettings();
    
    // The old state shows here rather than the updated one
    console.log(userSettings.enabled)
}

and this is my reducer:

const initialState = {
    settings = UserSettings,
};

export default (state = initialState, action) => {
    switch (action.type) {
        case SET_USER_SETTINGS:
            return {
                ...state,
                settings: action.settings,
            };
        default:
            return state;
    }
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

userSettings is a stale closure, as Nicolas suggested you cannot dispatch an action and expect the state value to have changed immediately because a new state is created after every action and your current function is still using the old value of the state. When the component re renders it will be re rendered with the new state value.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!