question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing children to withFormik component triggers warning

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
jaredpalmercommented, Feb 11, 2018

Children must be a fn

2reactions
LinusUcommented, Feb 12, 2018

@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 a children 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 pass children to me

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found