如何反转项目添加到 final-form/react-final-form-arrays 中的字段的顺序,所以最近的是第一个

How can I reverse the order that items are added to the fields in final-form/react-final-form-arrays so most recent is first

我正在使用 final-form/react-final-form-arrays 库是否有一种方法可以按最先出现的最新字段进行排序。 FieldArray 组件具有 fields 属性,它类似于数组但没有反向功能。所以每次我添加一个新字段时,例如 fields.push({newObject}) 我都希望渲染的组件位于列表的顶部。有人知道如何进行这项工作吗?

是的,有一种方法可以将值添加到顶部而不是底部。

简单替换

fields.push({});

fields.unshift({});

更多详细信息也可以在根自述文件中找到:https://github.com/final-form/react-final-form-arrays