final-form / react-final-form-arrays

A component for rendering and editing arrays 🏁 React Final Form
MIT License
205 stars 70 forks source link

Fields names getter #143

Open omerman opened 4 years ago

omerman commented 4 years ago

Hey, say I have this code:

type FormValues =  {
  x: [{id: number, value: string}]
}
 const { fields } = useFieldArray(
    "x",
    {
      isEqual,
      // re-render uppon array values change
      subscription: { value: true },
    }
  );

Now sometimes I don't need to use fields.map, say I want to render the item in the 5th cell, assuming I know it exists..

How would I get the prefix name of the cell? surely I can write "x[5].value", but I wanted something like ${field.names[5]}.value also maybe instead of fields.map, make it fields.names.map

Great library, thank you for final-form & react-final-form & this plugin :), looking forward for your response

omerman commented 4 years ago

Thought about it a bit more, maybe an api such as fields.get(5) that will return the string name prefix. since fields.names[index]/fields.names.map may break the current behavior.