fix($table): synchronize the colspan state of the table component #2237
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.
🤔 这个 PR 的性质是?
💡 需求背景和解决方案
table的合并单元格未能及时更新view:
commit1:
在使用Table组件的合并单元格功能时,发现在填充数据后的第一次update中没有合并单元格,需要强制再update一次才能正常合并。查看Table源码发现:控制单元格合并的状态skipSpansMap在表格数据发生变化时,仅对skipSpansMap进行了异步的原地修改,因此不能及时更新视图。
解决方案:在状态需要改变时,构建新的不可变数据,并使用useState返回的state setter来及时更新。
commit2:
考虑到react系统内的状态关联不必使用effect(You might not need an effect),加上rowspanAndColspan基本上是每次render时构建的匿名函数(缓存skipSpansMap意义不大),因此直接在useRowspanAndColspan hook最顶层直接同步计算skipSpansMap(200行*5列表格数据情况下,平均计算时长<0.5ms)。
📝 更新日志
fix(Table): 修复Table组件的【单元格合并配置】不同步。
本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单