I’m trying to understand how to use Redux Slices but all the tutorials seem to stop before using them, for example this one dev.tp.
I’ve implemented their example as far as it goes (and fixed the obvious code error but when I run the code the state does not increment.
Any idea what the issue is?
/* counterSlice.ts */
import { CounterSlice, createSlice } from 'npm:@reduxjs/[email protected]'
const counterSlice: CounterSlice = createSlice({
name: 'counter',
initialState: 0,
reducers: {
increment: (state, action) => state + 1,
decrement: (state, action) => state - 1,
},
})
export const { increment, decrement } = counterSlice.actions
export default counterSlice.reducer
/* index.ts */
import { configureStore, Store } from 'npm:@reduxjs/[email protected]'
import counterSlice from './counterSlice.ts'
import { increment, decrement } from './counterSlice.ts'
const store: Store = configureStore({
reducer: {
counter: counterSlice,
},
})
console.log(store.getState()) // { counter: 0 }
increment()
console.log(store.getState()) // { counter: 0 }