question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`styles` prop validation

See original GitHub issue

I, with many of us, use your ESLint config preset, which is great. It happens there are rules I don’t like and I override them.

I am not sure about react/forbid-prop-types rule and its setting, which is following:

'react/forbid-prop-types': ['error', { forbid: ['any', 'array', 'object'] }],

I find it very useful, but hate it when it comes to styles prop. This is no-go with default preset:

Label.propTypes = {
  styles: PropTypes.object.isRequired,
};

To validate (and satisfy ESLint) I have to use shape validation rule and write down rules for all styles passed by decorator function - repeated work here. Since styles is defined in very same file and there is very little that could go wrong, I don’t feel like paying special attention to that prop.

How do you validate styles prop at AirBnb?

Thanks for answer!


Okay, to be honest I often abuse vague shape validator function, without specifying actual shape of styles prop.

Label.propTypes = {
  styles: PropTypes.shape().isRequired,
};

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
ljharbcommented, Oct 31, 2017

Actually this is now done; import { withStylesPropTypes } from 'react-with-styles' - now you never need to (nor should) explicitly specify the styles or theme props in your code.

1reaction
Andreycocommented, Nov 8, 2016

Will take a look into this. Are you open to PRs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >
How to validate React props using PropTypes - LogRocket Blog
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >
ReactJS - Props Validation - Tutorialspoint
Properties validation is a useful way to force the correct usage of the components. This will help during development to avoid future bugs...
Read more >
What is the prop type for StyleSheet validation - Stack Overflow
It seems that the type number was valid since it's the actual styles are saved in an aggregated styles object ...
Read more >
Validate Custom React Component Props with PropTypes
Style React Components with className and inline Styles ... But if you're not using TypeScript, you can still use PropTypes to get runtime...
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