I am attempting to use react-spring's useSprings
to enable users to reorder the items in a formik FieldArray
. The useSprings Draggable List demo (found here) uses useRef
to manage the order of items. FieldArray
comes with a number of array helper functions for inserting, removing, and moving items.
The issues that I'm having are:
1) Re-ordering existing items using formik's move
array helper method successfully changes the array order, but requires an additional click to render the correct order
2) Adding or removing array items using array helper methods produces unexpected results. Mutating the length of the ref doesn't change the length of order.current
inside of useGesture
I've also tried using useState
instead of useRef
and updating the state with useEffect
when props change.
Here is a code sandbox I made: https://codesandbox.io/s/usesprings-with-fieldarray-56bex
In the bind
function, commenting out
order.current = newOrder;and uncommenting
// arrayHelpers.move(currIndex, currRow);shows issue #1 that I mentioned above.
I would like to be able to use formik's move
, insert
, and remove
helper functions with react-spring to seamlessly re-order, add, and delete items within a FieldArray
.