React Hooks & useCallback & useMemo
https://reactjs.org/docs/hooks-reference.html#usecallback
bug
const [unmount, setUnmount] = useState(false);
const widthRef = useRef(null);
// useCallback()
const refClick = (isFirst = true) => {
const dom = ReactDOM.findDOMNode(widthRef.current);
const width = dom ? dom.getBoundingClientRect().width : 50;
return isFirst ? (width - 50) : width;
};
useEffect(() => {
if(!unmount) {
// refClick();
// useCallback(refClick);
}
return () => {
setUnmount(true);
};
}, [unmount,]);
// }, [unmount, refClick]);
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!