Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Person.propTypes-related warnings #1228

Open
baadaa opened this issue Aug 23, 2021 · 0 comments
Open

Person.propTypes-related warnings #1228

baadaa opened this issue Aug 23, 2021 · 0 comments

Comments

@baadaa
Copy link
Contributor

baadaa commented Aug 23, 2021

Concern:

Incorrect data.js entries generate warnings in dev console. See the screenshot below.

image

PropType declared in /src/components/Person.js looks like the following. As someone enters flipphone as phone value or/and mac as `computer, it spits a warning in console.

Person.propTypes = {
  currentTag: PropTypes.string,
  person: PropTypes.shape({
    github: PropTypes.string,
    name: PropTypes.string,
    url: PropTypes.string,
    emoji: PropTypes.string,
    description: PropTypes.string,
    tags: PropTypes.arrayOf(PropTypes.string),
    country: PropTypes.string,
    computer: PropTypes.oneOf(['apple', 'windows', 'linux']),
    phone: PropTypes.oneOf(['iphone', 'android', 'windowsphone']),
    twitter(props, propName, componentName) {
      if (!/^@?(\w){1,15}$/.test(props[propName])) {
        return new Error(
          `Invalid prop \`${propName}\` supplied to` +
            ` \`${componentName}\`. This isn't a legit twitter handle.`
        );
      }
    },
  }),
};

Suggestion:

  • Clearly and explicitly indicate valid values for those fields in Pull Request template
  • Update the PropType declaration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant