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.

Wrapping propTypes with an environment check instead of removing them

See original GitHub issue

Would it be feasible to wrap propType definitions in a if (process.env.NODE_ENV !== 'production') check (extracting them out first if they’re part of a React.createClass()) instead of removing them completely?

This plugin is great and solves the problem of removing my own redundant propTypes for production, but it would be cool if it could also be adopted by authors transpiling reusable components to publish to npm, so your dependencies’ propTypes could be available in development and test as normal, but automatically removed for production via the usual dead-code elimination process.

Could that be made an option into this plugin? Remove vs. move/wrap?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jul 27, 2016

@insin I have done a first iteration for this feature. I still miss the stage-1 class static syntax.

0reactions
oliviertassinaricommented, Jul 28, 2016

@insin I’m gonna add it to Material-UI too 🎉 . However, I haven’t tested it on a real project yet. ⚠️ It’s still experimental.

I have two unsupported cases:

  • The old React.createClass.
  • The unnamed class. That should only be edges cases that we could support with more effort.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrap 'prop-types' usage in environment check conditional #682
Solution: libraries should wrap their prop-types usage in if (process.env.NODE_ENV !== 'production) { ... } , and that Babel plugin does this ...
Read more >
Remove unnecessary React propTypes from the production ...
Remove React propTypes from the production build, as they are only used in development. You can save bandwidth by removing them.
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 >
How To Create Wrapper Components in React with Props
js. Inside, remove diet from the destructured object and instead collect the rest of the props into a variable called props .
Read more >
Don't Call PropTypes Warning - React
In a future major release of React, the code that implements PropType validation functions will be stripped in production. Once this happens, any...
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