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
Copy file name to clipboardExpand all lines: README.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6535,7 +6535,7 @@ Technically it is possible to write nested function components but it is not sug
6535
6535
6536
6536
281. ### Can you combine **useReducer** with **useContext**?
6537
6537
6538
-
Yes, it's common to **combine** `**useReducer**` **with** `**useContext**` to build a lightweight state management system similar to Redux:
6538
+
Yes, it's common to combine**useReducer**with**useContext** to build a lightweight state management system similar to Redux:
6539
6539
6540
6540
```js
6541
6541
constAppContext=React.createContext();
@@ -6550,6 +6550,36 @@ Technically it is possible to write nested function components but it is not sug
6550
6550
}
6551
6551
```
6552
6552
6553
+
**[⬆ Back to Top](#table-of-contents)**
6554
+
6555
+
282. ### Can you dispatch multiple actions in a row with useReducer?
6556
+
Yes, you can dispatch multiple actions in a row using `useReducer` but not directly in one call. You'd have to call dispatch multiple times or create a composite action in your reducer that performs multiple updates based on the action type.
6557
+
6558
+
**Example: Dispatching Multiple Actions**
6559
+
You can define a custom function with dispatching actions one by one.
6560
+
```js
6561
+
functionhandleMultipleActions(dispatch) {
6562
+
dispatch({ type:'increment' });
6563
+
dispatch({ type:'increment' });
6564
+
dispatch({ type:'reset' });
6565
+
}
6566
+
```
6567
+
After that, you need to invoke it through event handler
0 commit comments