xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

React Hooks & useCallback & useMemo

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 发布文章使用:只允许注册用户才可以访问!


posted @ 2019-11-08 11:22  xgqfrms  阅读(66)  评论(2编辑  收藏  举报