hooks icon indicating copy to clipboard operation
hooks copied to clipboard

fix(useSize): 修改获取尺寸问题

Open pandaCure opened this issue 2 years ago • 2 comments

🤔 This is a ...

  • [ ] New feature
  • [] Bug fix
  • [ ] Site / documentation update
  • [ ] Demo update
  • [ ] TypeScript definition update
  • [ ] Bundle size optimization
  • [ ] Performance optimization
  • [ ] Enhancement feature
  • [ ] Internationalization
  • [x] Refactoring
  • [ ] Code style optimization
  • [ ] Test Case
  • [ ] Branch merge
  • [ ] Other (about what?)

💡 Background and solution

const App = () => {
    const ref = useRef(null);
    const width = useSize(ref);
    // console.log(51) error
    return <div style={{fontSize: '12px'}} ref={ref}>前程似锦.</div>
}

这里应该获取的实际宽度,而不是可见宽度

pandaCure avatar Nov 08 '23 12:11 pandaCure

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Nov 08 '23 12:11 CLAassistant

相关 issue/PR

  • https://github.com/alibaba/hooks/issues/2114
  • https://github.com/alibaba/hooks/issues/2227
  • https://github.com/alibaba/hooks/issues/1302
  • https://github.com/alibaba/hooks/pull/1303

useSize 存在的问题在上述 issue/PR 的评论区,包含的问题有:“获取精度问题、DOM 尺寸计算规范问题 和 scale 下的尺寸问题”

这个 PR 肯定是 breaking changes 的,先留着,v4 会统一处理哈~

liuyib avatar Nov 09 '23 02:11 liuyib

不能这么改,参考https://github.com/alibaba/hooks/pull/2482 这个pr

crazylxr avatar Apr 21 '24 09:04 crazylxr