locked
a quick formik fieldarray question RRS feed

  • Question

  • User1034446946 posted

    i have a formik field array, in a form, its just an array of objects the object has a startDate, and endDate and an id

    in the docs have a component call FieldArray which has props which are the arrayHelper methods and all is find

    however thats where the docs information to field arrays ends, and here is my issue

    how do i build a component which loops through the array? the fieldarray component doesn't have its own values,although you can access them  via the form prop but that means the props will change on every element change, the field array doesn't allow me to addmy own props (or at least when i look at the props it doesn't show in the console, the connect options has the same issue with using the form values.

    i have it working at the moment using the form props values which i really don't like, and can't think of a good reason or way arround the field array no having its own values.

    Any suggestions would be appriciated.

    Thursday, October 24, 2019 2:02 AM

Answers

  • User-474980206 posted

    I fail to understand your question. The field array is to handle the common case where the form state contain an array of objects, and you want to render a common template for each item in the array. The array helper methods are just for adding, removing, moving items items in the array, without having to write the update state management code. 

    to loop thru the array, it just part of the form objects, you don’t need the array handlers, just use the standard Array.map method.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 24, 2019 4:01 PM

All replies

  • User1034446946 posted

    hmmm do i just use  a normal field component for the array information?

    although thats still messy as it means the arrayhelpers is seperate from the array fields, eg i want to use the remove inline with the form fields and the add outside, it would be simple if the fieldarray value was passed into the fieldarray component.

    Thursday, October 24, 2019 2:06 AM
  • User-474980206 posted

    I fail to understand your question. The field array is to handle the common case where the form state contain an array of objects, and you want to render a common template for each item in the array. The array helper methods are just for adding, removing, moving items items in the array, without having to write the update state management code. 

    to loop thru the array, it just part of the form objects, you don’t need the array handlers, just use the standard Array.map method.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 24, 2019 4:01 PM
  • User1034446946 posted

    after writing a long reply, i am a dumb ass, basically i wanted to put the whole div row in component, i can put put the fields i need,although i think its messy

    Thursday, October 24, 2019 10:49 PM