import { createSlice } from '@reduxjs/toolkit';
// Step 1: Define the initial state for the counter
const initialState = {
value: 0,
};
// Step 2: Create the slice with reducers for increment, decrement, and reset
const counterSlice = createSlice({
name: 'counter',
initialState,
reducers: {
increment: (state) => {
state.value += 1; // Increase the counter by 1
},
decrement: (state) => {
state.value -= 1; // Decrease the counter by 1
},
reset: (state) => {
state.value = 0; // Reset the counter to 0
},
},
});
// Step 3: Export the actions and the reducer
export const { increment, decrement, reset } = counterSlice.actions;
export default counterSlice.reducer;