Dani
Dani

Reputation: 2488

Flow is missing props validation when setting default values on an object

I got a React Functional component which takes a List as props.

const Dashboard = (props: { items: List } = { items: List() }) => {
  const { items } = props
  ...
})

However, the items in const { items } = props produces the following error:

error 'items' is missing in props validation react/prop-types

The FlowType docs give an example:

ES2015 features Default values assigned to parameters must come after the parameter’s type annotation:

function foo (P1: T1 = V): U { .. }

But it's not really clear to me how this applies to objects

Upvotes: 3

Views: 1271

Answers (1)

Wietse Venema
Wietse Venema

Reputation: 2764

This is in fact not a flow error but this eslint error:

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md

You can resolve your error by disabling the eslint rule if you don't care about proptype now that you use flow.

Or you add a proptype, which is less specific than flow, but runtime.

Dashboard.propTypes = {
  items: React.PropTypes.object
};

Upvotes: 5

Related Questions