console
console.log(1&&undefined||2)
console.log(1?undefined:2)
console.log(String(NaN))
console.log(String([]))
console.log(String([NaN,undefined,null]))
console.log([NaN,undefined,null].join())
console.log([NaN,undefined,null].toString())
忘掉生命周期 不然就会忘掉hooks
理解Capture Value之后 Function Component才能用的顺手
快照Immutable ref mutable
形象理解就是每次render就拍一次快照,固化了状态和属性。
setState数一数从上到下一一对应。
想拿最终状态从ref拿
effect会重复调用,用了什么属性记得加到第二个参数里做性能优化
要用const声明 要用setXXX赋值
需要注意的是,这里的useEffect的第二个参数必须传空数组,这样它就等价于只在componentDidMount的时候执行。如果不传第二个参数的话,它就等价于componentDidMount和componentDidUpdate
监听事件与取消监听
useEffect(() => {
addEventListener();
return removeEventListener;
}, []);
https://segmentfault.com/a/1190000018639033
https://codesandbox.io/s/react-hooks-demo-3-0wz50
https://www.cnblogs.com/chenjg/p/10327304.html