react 里面的 useEffectEvent 的执行原理是怎样的?-灵析社区

Fronttend

你可以理解为保证函数引用,但是函数内部状态依旧更新,类似这段伪代码 function useEffectEvent(handler) { const handlerRef = useRef(null); useLayoutEffect(() => { handlerRef.current = handler; }); return useCallback((...args) => { const fn = handlerRef.current; return fn(...args); }, []); }

阅读量:1

点赞量:0

问AI