Passing children to withFormik component triggers warning
See original GitHub issueI’ve just ran into a small problem with an warning triggered when using withFormik
on a component that receives children
as a prop.
Warning: You should not use <Formik render> and <Formik children> in the same <Formik> component; <Formik children> will be ignored
My use case is a generic confirm page, where the children passed in will be rendered inside a container, with a checkbox and confirm button underneath:
import React = require('react')
import { FormikProps, FormikBag, withFormik } from 'formik'
import Checkbox from '../components/checkbox'
import { FormikContainer, CancelButton, SubmitButton, P } from '../components/layout'
interface ConfirmPageProps {
confirmText: string
loadingText: string
submitTitle: string
children?: React.ReactNode
onCancel: () => void
onConfirm: () => void
}
interface ConfirmFormValues {
understood: boolean
}
function mapPropsToValues () {
return { understood: false } as ConfirmFormValues
}
function handleSubmit ({}: ConfirmFormValues, { props }: FormikBag<ConfirmPageProps, ConfirmFormValues>) {
props.onConfirm()
}
function render ({ values, isSubmitting, ...props }: ConfirmPageProps & FormikProps<ConfirmFormValues>) {
return (
<FormikContainer maxWidth='320px' justifyContent='center'>
{props.children}
<P>
<Checkbox name='understood' label={props.confirmText} />
</P>
<P textAlign='center'>
{isSubmitting && props.loadingText}
{isSubmitting || <SubmitButton title={props.submitTitle} disabled={!values.understood} />}
{isSubmitting || <br />}
{isSubmitting || <CancelButton title='Cancel' onClick={props.onCancel} />}
</P>
</FormikContainer>
)
}
export default withFormik({ mapPropsToValues, handleSubmit })(render)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Warning: Formik called `handleBlur`, but you forgot to pass an ...
I know the problem is with the input component that doesn't have the built in name property. Component is called 'Search', but if...
Read more >API Reference - Formik
Warning : <Formik component> takes precendence over <Formik render> so don't use both in the same <Formik> . render: (props: FormikProps<Values>) => ReactNode....
Read more >formik pass props to component - You.com | The AI Search ...
The render function passed as child to <Formik> has single argument props , which includes handleReset() : In the following example, handleReset() is ......
Read more >Using Formik to Handle Forms in React - CSS-Tricks
We'll start with a React component then integrate Formik while demonstrating ... We can pass those to useFormik , <Formik/> or withFormik ....
Read more >How to Trigger a Form Submit in Child Component with Redux
In this guide, we will discuss how to consolidate data from different child components and submit them. Building the Form Component. two fields: ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Children must be a fn
@jaredpalmer I’m not sure what you mean by “Children must be a fn”
The problem here is that I have built a React Component using
withFormik
, and that component in itself accepts achildren
parameter from whoever is using this component.Thus I’m not trying to pass
children
at all to formik, but just want the consumers of my component to passchildren
to me