Understanding "PropType is defined but prop is not never used" + Formik

See original GitHub issue

Hello all!

I am making a Formik form and ESLint was complaining about some props missing validation. Then, I added propTypes and defaults and I got the error “PropType is defined but prop is never used”.

I believe this error is due to the fact that when I place MyComponent.propTypes blabla I was assigning props to my functional components. However, ESLint complains about the props passed to the render prop function. An example of such props are errors and touched from the function ValidationSchemaExample on https://jaredpalmer.com/formik/docs/guides/validation

In my personal code I had something like this:

  const renderResetPasswordRequestForm = ({ errors, touched, handleSubmit } ) => {
    return (
      <form onSubmit={handleSubmit}>
      </form>
    );
  };

Which was triggering the error, however, with the below code it does not happen:

const renderResetPasswordRequestForm = formikProps => {
    const { errors, touched, handleSubmit } = formikProps;
    return (
      <form onSubmit={handleSubmit}>
      </form>
    );
  };

So the key question: Anyone understand why if I destructure the parameters it complains and if I do so in the body of the function ESLint does not complain?

Thank you in advance and regards.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jzabalacommented, Jul 7, 2020

I just tested this issue with the changes in #2699 and since functions not starting with an uppercase letter are not considered components the error about props not being defined on render props it not triggered.

1reaction
golopotcommented, Nov 14, 2019

The bug seems to be that the variable name must be named props:

// works
function Foo(props) {
  ...
}

// fails
// `propsss` is not recognized as props
function Goo(propsss) {
  ...
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding "PropType is defined but prop is not never ...
Hello all! I am making a Formik form and ESLint was complaining about some props missing validation. Then, I added propTypes and defaults ......
Read more >
PropType is defined but prop is never used - Stack Overflow
This should fix your problem, let's de-structure your props and then assign propTypes to your stateless component.
Read more >
Tutorial - Formik
Throughout this tutorial, we touched on Formik concepts including form state, fields, validation, hooks, render props, and React context. For a more detailed ......
Read more >
Don't Call PropTypes Warning - React
Don't call PropTypes directly​​ Using PropTypes in any other way than annotating React components with them is no longer supported: var apiShape =...
Read more >
React Form Validation With Formik And Yup
We'll learn how it can be used incrementally with HTML input fields and custom validation rules. Then we will set up form validation...
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