简体   繁体   中英

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

Im using final-form/react-final-form-arrays library is there a way to sort by most recent field appearing first. The FieldArray component has the fields prop which is array like but does not have a reverse function. So each time I add a new field eg fields.push({newObject}) I want that rendered component to be at the top of the list. Anyone know how to make this work?

Yes, there is a way to add values to the top instead of the bottom.

Simply replace

fields.push({});

with

fields.unshift({});

More details can also be found in the root readme: https://github.com/final-form/react-final-form-arrays

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM