Closed dancerphil closed 4 years ago
const useState = createState(); const useReducer = createReducer(); const useMemo = createMemo(); // 以此类推
react hooks 提供了依托组件生命周期的 hooks,而 region-hooks 提供了依托 Application lifecycle 的 hooks
数据共享
无视 react hooks 关于调用顺序的限制,可以先提前 return,然后调起 hooks(存疑,部分需要挂载 react 组件生命周期的就不行)
更广范围内的 memoize,比如跨组件 useMemo,相当于原先的 reselect
一旦全局的 hooks 需要挂载 react 组件生命周期,上述部分特性会失效,所以这套东西还是不太有戏。
除此之外,跨组件 useMemo 好像也有点问题,要保证 b = f(a) 和 b = f'(a) 成立就要约定 f = f',不约定的话又没用,也是个鸡肋。
b = f(a)
b = f'(a)
f = f'
主要 api
与 react 的区别
react hooks 提供了依托组件生命周期的 hooks,而 region-hooks 提供了依托 Application lifecycle 的 hooks
应用生命周期的 hooks 有什么特性?
数据共享
无视 react hooks 关于调用顺序的限制,可以先提前 return,然后调起 hooks(存疑,部分需要挂载 react 组件生命周期的就不行)
更广范围内的 memoize,比如跨组件 useMemo,相当于原先的 reselect