createSlicebeginnerconst { createSlice } = ReduxToolkit
const counterSlice = createSlice({
name: 'counter',
initialState: { value: 0 },
reducers: {
increment(state) { state.value += 1 },
},
})
counterSlice.actions.increment() // β { type: 'counter/increment' }createSlice bundles the reducer and action creators together β no need to write action type constants manually.
createSlice is the recommended way to write Redux logic. It generates action creators and action types automatically based on the reducer names you provide.
Challenge: Create a counter slice with:
name: 'counter'initialState: { value: 0 }increment that increases value by 1counterSlice.name // β 'counter'
counterSlice.actions.increment().type // β 'counter/increment'