I'm using Formik on Next.js in combination with a library called next-auth. This library uses JWT authentication and a React hook to populate a client-side session variable with some user data.
I've written a function getInitialValues that uses data from the session variable to request additional data from my API. I then want to populate the form's initial values with that data.
It's definitely fetching that data from the API because it's all showing up in my error message debug element. But I can't seem to populate initialValues with that data even though I have enableReinitialize={true} set.
Here is the basic structure of my code:
import { useState } from 'react';
import { useSession } from 'next-auth/client';
import fetch from 'unfetch';
import { Formik } from 'formik';
❓Question
I'm using Formik on Next.js in combination with a library called next-auth. This library uses JWT authentication and a React hook to populate a client-side
session
variable with some user data.I've written a function
getInitialValues
that uses data from thesession
variable to request additional data from my API. I then want to populate the form's initial values with that data.It's definitely fetching that data from the API because it's all showing up in my error message debug element. But I can't seem to populate
initialValues
with that data even though I haveenableReinitialize={true}
set.Here is the basic structure of my code:
[…]
[…]
Am I doing something wrong here? Do I need to manually reset the form somehow once the values are returned from
getInitialValues()
?