-
After removing an element of a field array with the remove helper, I want to adjust some metadata in the other array elements, but there appears to be no way to access the updated values from within the handler. (Any So to clarify, here's a schematic of the problem
Here, An obvious approach would be to just handle the remove directly instead of using Is there a way to access an updated state (i.e., Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In v2 you need to use an effect for this because it relies solely on hooks. In v3 we will most likely provide an escape hatch in the form of const { values, setValues } = useFormikContext();
// deleteEntryHandler etc
// ...
useEffect(() => {
setValues(updateStuffInRemainingEntries(values.yourArrayFieldName));
}, [values.yourArrayFieldName]);
return <div><YadaYada onClick={deleteEntryHandler} /></div>; |
Beta Was this translation helpful? Give feedback.
In v2 you need to use an effect for this because it relies solely on hooks. In v3 we will most likely provide an escape hatch in the form of
getState()
to get the latest state in "the future".