Apex

Results 3 comments of Apex

@LastStranger > react-hooks时代貌似改写了这种方式,我用react-hooks写法写出来的结果都是0 更新的方式没有更改,首先是因为useEffect函数只运行了一次,其次setTimeout是个闭包,访问到的值一直是0(按照正常的写法setVal(val+1))。以例子来看的话,并没有执行更新的操作。 具体可以参考 issue讨论: https://github.com/facebook/react/issues/14010

![image](https://user-images.githubusercontent.com/22948950/62672917-02ed8480-b9cf-11e9-91f8-9168a4b34d45.png) ![image](https://user-images.githubusercontent.com/22948950/62673067-84451700-b9cf-11e9-837f-8dd5f6956202.png) 这... 难道是我的chrome比较新?为什么得到的答案完全不一样

```js // 借用一下前面的 function traversal(node) { if(!node){ console.log(node); return; } const stack = Array.from(node); // 获取的是 HTMLNodes 类数组对象,转成数组 while(stack.length > 0) { const elem = stack.pop(); if (elem && elem.nodeType...