【问题标题】:Performance trouble with FieldArray in react-final-formreact-final-form 中 FieldArray 的性能问题
【发布时间】:2024-01-23 08:27:01
【问题描述】:
我创建了一个应用程序,其中使用了 react-final-form 中的 FieldArray 组件。我的 Array 组件存在性能问题。每个组件还包含大约 8 个字段(每个字段都包含验证规则)(也来自 react-final-form),当我添加 50 多个元素时应用程序的滞后(同时将所有组件渲染到虚拟 DOM 并将其与当前 DOM 进行比较)。有人遇到过这个问题吗?
我怎样才能避免这种情况?
【问题讨论】:
标签:
reactjs
performance
final-form
【解决方案1】:
为防止整个列表重新呈现,您可以清除 FieldArray 组件中的所有订阅。
<FieldArray
name="myList"
subscription={{}} // This is required so that the whole array does not re-render on any change.
render={(fieldsProps) => (fieldsProps.fields.map((name, index) =>
{ (...your function here...) })
/>