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
Redux Toolkit provides a `configureStore` function that simplifies store creation. It includes good defaults and automatically sets up the Redux DevTools extension.
A slice is a collection of Redux reducer logic and actions for a single feature of your app. Redux Toolkit’s `createSlice` function automatically generates action creators and action types.
Now that the store and slice are set up, you can use them in your React components. Use the `useSelector` hook to read state and the `useDispatch` hook to dispatch actions.
92
90
93
-
```javascript
94
-
// src/features/counter/Counter.js
91
+
```javascript title = "src/features/counter/counter.js
Copy file name to clipboardExpand all lines: courses/react-js/advanced-level/redux-toolkit/lesson_2.md
+4-8Lines changed: 4 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,7 @@ Creating an API utility for your application is an essential step to manage and
25
25
26
26
You'll often want to separate your API calls into a dedicated utility file. This approach allows you to centralize the logic for making HTTP requests, making your code more modular and easier to maintain.
27
27
28
-
```javascript
29
-
// src/features/posts/postsAPI.js
28
+
```javascript title = "src/features/posts/postsAPI.js"
With the API utility created, you can now use it in your Redux slices to handle asynchronous actions. Redux Toolkit provides `createAsyncThunk` to simplify this process.
42
41
43
-
```javascript
44
-
// src/features/posts/Posts.js
42
+
```javascript title = "src/features/posts/Posts.js"
Redux Toolkit provides `createEntityAdapter` to manage normalized state more efficiently. It includes helpers for common operations like adding, updating, and removing entities.
You can write your own custom middleware to handle specific tasks. Middleware is a function that returns another function, which receives the `next` function and the `action`.
Sometimes you may want to reuse the same logic in different parts of your application. You can create a reusable slice that can be configured for different use cases.
0 commit comments