In my React game, I use a React library called Formik for a form.
In it, you set the initial values for the form like this:
<Formik
initialValues={{
characterClasses: ["1", "3", "9"],
race: "Elf",
name: "Derolt",
age: "84",
..etc
But now, I'm in a situtation where I want to load the initial values from an API call.
So I created this:
const fetchGameCharData = async (gameId) => {
const game = await axios("api/games/" + gameId);
// return the result
return game;
};
My problem is, I can't figure out how to use the above fetch method to actually populate the initialValues part that Formik uses.
Has anyone ever done this?
Thanks!