You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a new file named `src/features/counter/counterSlice.ts`. In that file, import the `createSlice` API from Redux Toolkit.
82
+
Add a new file named `src/features/counter/counter-slice.ts`. In that file, import the `createSlice` API from Redux Toolkit.
83
83
84
84
Creating a slice requires a string name to identify the slice, an initial state value, and one or more reducer functions to define how the state can be updated. Once a slice is created, we can export the generated Redux action creators and the reducer function for the whole slice.
85
85
86
86
Redux requires that [we write all state updates immutably, by making copies of data and updating the copies](https://redux.js.org/tutorials/fundamentals/part-2-concepts-data-flow#immutability). However, Redux Toolkit's `createSlice` and `createReducer` APIs use [Immer](https://immerjs.github.io/immer/) inside to allow us to [write "mutating" update logic that becomes correct immutable updates](https://redux.js.org/tutorials/fundamentals/part-8-modern-redux#immutable-updates-with-immer).
87
87
88
-
```js title="features/counter/counterSlice.ts"
88
+
```js title="features/counter/counter-slice.ts"
89
89
import { createSlice } from"@reduxjs/toolkit";
90
90
91
91
exportconstcounterSlice=createSlice({
@@ -124,7 +124,12 @@ Next, we need to import the reducer function from the counter slice and add it t
0 commit comments