Hailwood
Hailwood3y ago

Hailwood – 00-02 Mar 3

Hey folks, using formik with typescript, we have the render function (as children). Typescript knows values is of type FormikValues and knows the exact keys/type of values inside values based off initialValues. I'm wondering if we can make a prop of a component rendered inside this render function be required to be a key of values? I.e.
<Formik initialValues={{name: 'bob', age: 32}}>
{({values}) => {

console.log(
values.name, //okay
values.email // errors as it should
);

//I want to do this
return (
<>
{/* okay as name is in initial values */}
<MyFieldComponent name="name" />

{/* should error as email is not in initial values */}
<MyFieldComponent name="email" />
</>
);

}};
</Formik>
<Formik initialValues={{name: 'bob', age: 32}}>
{({values}) => {

console.log(
values.name, //okay
values.email // errors as it should
);

//I want to do this
return (
<>
{/* okay as name is in initial values */}
<MyFieldComponent name="name" />

{/* should error as email is not in initial values */}
<MyFieldComponent name="email" />
</>
);

}};
</Formik>
1 Reply
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/902647189120118794/948731985143136256 Question not getting answered? Maybe it's hard to answer, or maybe you asked at a slow time. Check out these resources for help asking a good question: https://stackoverflow.com/help/how-to-ask http://wp.me/p2oIwo-26