facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Getting warnings for passing a component to another component as "children" #303

Closed scottc11 closed 4 years ago

scottc11 commented 4 years ago

I can't figure out how to get rid of this warning, and it is starting to irritate me 🤦‍♂️ahah. Can someone help? Is this a bug or am I doing something wrong?

I am simply passing one component to another component so it can wrap it with some boilerplate stuff, like so:

const Wrapper = (props) => {
  return (
    <div>
       {props.children}
    </div>
  )
}

const App = (props) => {
  return (
    <Wrapper>
      <SomeOtherComponent />
    </Wrapper>
}

See, this looks fine to me. It looks as all the examples online look. BUT, I still get the following warning.

Failed prop type: Invalid prop `children` of type `object` supplied to `Wrapper`, expected `function`

I am using prop-types@15.7.2 and react@16.8.6

ljharb commented 4 years ago

It can't be that simple; the error message strongly implies that Wrapper.propTypes is set to:

{
  children: PropTypes.function
}

Are you sure that's the exact, unmodified code that's producing that error?

scottc11 commented 4 years ago

turns out you are spot on 😔. I must have set this wrong ages ago and forgot about it. Sorry about that and thanks for your help.