File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed
Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -57,21 +57,22 @@ Render Props:
5757* React Hooks 的常见陷阱
5858 * 闭包陷阱, (useInterval, useFetch)
5959
60- ###
61- React Hooks 使用中的问题
60+ ### React Hooks 使用中的问题
6261
6362#### 百思不解, 必是闭包
6463
65- * demo1: 闭包陷阱1。 [ Demo 地址 ] ( https://codesandbox.io/s/22y21468r )
64+ * Part1: 闭包陷阱
6665
67- 1 . Hooks/class demo 对比演示;
68- 2 . Hooks/class 互相切换为对方的形态;
66+ > [ Demo 地址] ( https://codesandbox.io/s/22y21468r )
6967
70- 结论: 问题不在于是使用 Hooks 还是 class, 本质是受到闭包的影响。
68+ 1 . 函数组件/类组件 Demo 对比演示;
69+ 2 . 函数组件/类组件互相切换为对方的形态;
7170
72- * demo2: 闭包陷阱2
71+ 结论: 问题不在于是使用函数组件还是类组件, 本质是受到闭包的影响。
7372
74- 由 Class 转换过来的用户习惯 ` setCount(count + 1)) ` 的方式。但在 Hooks 中这样子使用会产生闭包问题导致 ` count ` 不会增加。
73+ * Part2: 闭包陷阱2
74+
75+ 之前写过类组件的用户应该习惯 ` setCount(count + 1)) ` 的方式。但在函数组件中这样子使用会产生闭包问题导致 ` count ` 不会增加。
7576
7677``` js
7778function Demo () {
@@ -91,9 +92,9 @@ function Demo() {
9192}
9293```
9394
94- 提供 3 种解法 。用户说还是想用 ` setCount(count + 1) ` 的形式怎么办
95+ 提供若干种解法 。用户说还是想用 ` setCount(count + 1) ` 的形式怎么办
9596
96- 引出为此提供 ` useInterval ` 钩子, 顺利过渡到 ` beast-hooks `
97+ 引出自定义 hooks 的概念。介绍 ` useInterval ` 钩子, 顺利过渡到 ` beast-hooks `
9798
9899``` js
99100function useInterval (callback , delay : number ) {
You can’t perform that action at this time.
0 commit comments