CJY0208 / react-activation

Hack <KeepAlive /> for React
https://www.npmjs.com/package/react-activation
MIT License
1.78k stars 140 forks source link

在KeepAlive 中无法获取元素的宽高信息 #283

Closed Dreamcreative closed 1 year ago

Dreamcreative commented 1 year ago
image
const Com = () => {
  useLayoutEffect(() => {
    const rt = document.querySelector(".com")?.getBoundingClientRect();
    console.log(rt);
  }, []);
  return <div className="com">获取元素高度</div>;
};
const AliveRecord = props => (
  <KeepAlive>
    <Com {...props} />
  </KeepAlive>
);
youngBrain1893 commented 1 year ago

这个是不是 .com 元素没获取到

CJY0208 commented 1 year ago

参考 https://github.com/CJY0208/react-activation/blob/master/README_CN.md#breaking-change-%E7%94%B1%E5%AE%9E%E7%8E%B0%E5%8E%9F%E7%90%86%E5%BC%95%E5%8F%91%E7%9A%84%E9%A2%9D%E5%A4%96%E9%97%AE%E9%A2%98 此处第 1 点