Redux Toolkit Not Updating State as Expected

clock icon

asked 1 year ago Votes

message

4 Answers

eye

91 Views

 

I'm dispatching the increment action, but the state is not updating as expected. What could be the issue, and how can I ensure that the state updates correctly when using Redux Toolkit?

 

import { createSlice } from '@reduxjs/toolkit';

const counterSlice = createSlice({
  name: 'counter',
  initialState: { value: 0 },
  reducers: {
    increment: (state) => {
      state.value += 1;
    },
  },
});

export const { increment } = counterSlice.actions;
export default counterSlice.reducer;

4 Answers

ype: Schema.Types.ObjectId, require: true, ref: 'User' },
question: { type: Schema.Types.ObjectId, require: true, ref: 'Question' },
upvotes: [{ type: Schema.Types.ObjectId, ref: 'User' }],
downvotes: [{ type: Schema.Types.ObjectId, ref: 'User' }],
content: { type: String, require: true },
createdAt: { type: Date, default: Date.now },
});

1

Write your answer here

Top Questions