Skip to content

Commit 8f5cba5

Browse files
committed
Add more reducer patterns!
1 parent 7806cd8 commit 8f5cba5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# React Reducer Patterns
22

3+
## One-Way Flag
4+
5+
```js
6+
const [isEnabled, enable] = useReducer(() => true, false);
7+
```
8+
9+
[Source](https://twitter.com/markdalgleish/status/1521304112738217984)
10+
11+
## Toggle Flag
12+
13+
```js
14+
const [on, toggle] = useReducer(flag => !flag, false)
15+
```
16+
17+
[Source](https://twitter.com/FernandoTheRojo/status/1521305729558274048)
18+
319
## Menu
420

521
```ts
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# JavaScript Key-Value Collections
2+
3+
- Map
4+
- URLSearchParams
5+
- FormData
6+
- Object
7+
- WeakMap
8+
9+
## Map
10+
11+
- **Pro:** keys can be any JavaScript value, not just strings.
12+
- **Con:** homogeneous TypeScript values.
13+
- 💡 Clone:
14+
```js
15+
const newMap = new Map(otherMap);
16+
```
17+
18+
## URLSearchParams
19+
20+
- Spec: serializes to `application/x-www-form-urlencoded`
21+
22+
## Objects
23+
24+
- Keys can be strings or symbols.

0 commit comments

Comments
 (0)