fix: Ellipsis
use ellipsisValueRef to reduce reflow
#226
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在一个有展开收起的例子中。比如
点击展开节点执行
setEllipsis(false);
会设置ellipsis属性值为false。这个时候在组件中,由于
https://github.com/arco-design/arco-design-mobile/blob/main/packages/arcodesign/components/ellipsis/components/js-ellipsis.tsx#L217-L222
这段代码,会在ellipsis变化的时候触发
resize
事件。https://github.com/arco-design/arco-design-mobile/blob/main/packages/arcodesign/components/ellipsis/components/js-ellipsis.tsx#L163-L177
但其实这个时候,
useEffect
还没有重新执行,所以resize事件触发执行reflow
的时候,拿到的ellipsis是旧值为true,进行了不必要的二分查找计算。使用ref来替换可以在reflow的时候拿到最新的值,从而避免这部分计算。