Skip to content

How to access (and update) values in component *after* using FieldArray helpers #3116

Answered by johnrom
genovese asked this question in Q&A
Discussion options

You must be logged in to vote

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".

    const { values, setValues } = useFormikContext();
    // deleteEntryHandler etc
    // ...
    useEffect(() => {
      setValues(updateStuffInRemainingEntries(values.yourArrayFieldName));
    }, [values.yourArrayFieldName]);

    return  <div><YadaYada onClick={deleteEntryHandler} /></div>;

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@johnrom
Comment options

johnrom Mar 25, 2021
Collaborator

@genovese
Comment options

Answer selected by genovese
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants