Eslint-plugin-react: prop-types rule should understand RelayContainer

Created on 9 Oct 2015  路  5Comments  路  Source: yannickcr/eslint-plugin-react

None of the Relay examples specify propTypes, probably because the propTypes are specified indirectly by the RelayContainer 'fragments'. Explicit specification of propTypes would be duplicate information.

Should relay users simply disable the prop-types rule, or can it be made to detect a RelayContainer and use it to validate props?

enhancement help wanted rule

Most helpful comment

For some context the following component should not generate errors with the prop-types rule:

import React from 'react'
import Relay from 'react-relay'

function User ({ user }) {
  return <div>{user.name}</div>
}

export default Relay.createContainer(User, {
  fragments: {
    user: () => Relay.QL`
      fragment on User {
        name
      }
    `,
  },
})

All 5 comments

I need to investigate on this, since I've never used Relay myself.

But I would accept a PR for this ;)

For some context the following component should not generate errors with the prop-types rule:

import React from 'react'
import Relay from 'react-relay'

function User ({ user }) {
  return <div>{user.name}</div>
}

export default Relay.createContainer(User, {
  fragments: {
    user: () => Relay.QL`
      fragment on User {
        name
      }
    `,
  },
})

I don't think the propTypes info duplicates the Relay fragment. Similar, but still useful to know both.

Also, writing out the PropTypes is good so that in the future you could strip Relay from a component and still know it's data requirements.

Also, a rule doing this would not be able to tell you if you were getting a string (from Relay) but actually meant to be getting a number. That's something that PropTypes can check by being between the two.

I think that handling special cases of "not React components" is out of scope of this plugin, and "always providing propTypes" is a strong best practice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

inian picture inian  路  3Comments

budarin picture budarin  路  3Comments

ljharb picture ljharb  路  3Comments

otakustay picture otakustay  路  3Comments

AaronHarris picture AaronHarris  路  3Comments