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

143
Views
Redux state isn't updating

Hello I have a problem with redux. It seems like state doesn't change. I'm using redux toolkit. The problem is in Main.js. When I call useEffect it sends request to database and should dispatch action. And this is working. I can see that reducer executes but that doesn't change the state value. I don't know why.

configSlice.js

const configSlice = createSlice({
name: "config",
initialState: null,
reducers: {
    saveConfig(state, action) {
        state = action.payload;
        console.log(state);
    },
    resetConfig(state) {
        state = null;
    },
},
});

export const configSliceActions = configSlice.actions;
export default configSlice;

Main.js

const Main = () => {
    const dispatch = useDispatch();
    const user = useSelector((state) => state.auth.user);
    const config = useSelector((state) => state.config);
    useEffect(() => {
        if (user) {
            get(ref(database, `${user.uid}/config`)).then((snapshot) => {
                if (snapshot.exists()) {
                    dispatch(configSliceActions.saveConfig(snapshot.val()));
                }
            });
        }
    }, []);
    if (!user) {
        return <Redirect to="/login" />;
    }
    if (!config) {
        return <ConfigPanel />;
    }
    return <div></div>;
};
export default Main;
about 4 years ago · Juan Pablo Isaza
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!