Wrapping propTypes with an environment check instead of removing them
See original GitHub issueWould 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:
- Created 7 years ago
- Reactions:3
- Comments:5 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@insin I have done a first iteration for this feature. I still miss the stage-1 class static syntax.
@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:
React.createClass.