Skip to content

Commit 7765cdc

Browse files
committed
More react reducer patterns improvements
1 parent 8302ccf commit 7765cdc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/components_guide_web/templates/react_typescript/reducer-patterns.html.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# React `useReducer` patterns
1+
# React Reducer Patterns
22

33
## Menu
44

@@ -27,3 +27,13 @@ tap("edit") // "edit"
2727
tap("edit") // null
2828
tap(null) // null
2929
```
30+
31+
You can of course condense it to a ternary if you want:
32+
33+
```ts
34+
// You can of course shorten it into a ternary if you really want:
35+
const [openMenu, tap] = useReducer(
36+
(current: Menu, action: Menu) => (action === current) ? null : action,
37+
null
38+
);
39+
```

0 commit comments

Comments
 (0)