hooks
hooks copied to clipboard
fix(useSize): 修改获取尺寸问题
🤔 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>
}
这里应该获取的实际宽度,而不是可见宽度
相关 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 会统一处理哈~
不能这么改,参考https://github.com/alibaba/hooks/pull/2482 这个pr