Ability to disable babel-plugin-transform-react-remove-prop-types
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
I was upgrading from v.3 to v.6 and one of the changes was related to the next/babel preset. The preset contains the babel-plugin-transform-react-remove-prop-types plugin, which previously was easy to remove (filtering based on names). The plugin needs to be removed because propTypes carry metadata used in the documentation and also because of Object.keys(propTypes)
, which is useful for omitting known props when passing them to the child:
class Foo extends Component {
static propTypes = {
onZing: PropTypes.func.isRequired,
};
render() {
// Note that onZing is not used in render, but rather in another method;
// In my experience more complicated components benefit greatly from Object.keys(propTypes)
return (
<Bar
{...omit(this.props, Object.keys(Foo.propTypes)
onClick={this.handleClick}
/>
);
}
handleClick = () => {
this.props.onZing();
};
}
Right now filtering plugins by names is not possible, so I’d like to have an option to remove the plugin.
Describe the solution you’d like
I’d like to be able to pass an option to the preset that would prevent the inclusion of babel-plugin-transform-react-remove-prop-types even in production environment. It could be used as such:
process.env.NODE_ENV === 'production' &&
get(opts, 'react-remove-prop-types', true) &&
require('babel-plugin-transform-react-remove-prop-types')
where get
is lodash/get
or its equivalent.
Describe alternatives you’ve considered
For now I have this condition in place:
plugins = plugins.filter(
plugin => (
!plugin.default ||
!plugin.default.toString().includes('react-remove-prop-types')
)
)
This is far from ideal, because it depends on the contents of the plugin functions. Some of the functions are bound and have [native code]
as a source, so it’s only by luck that the plugin can be discovered.
Additional context
As usual, I volunteer to prepare a PR.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top GitHub Comments
babelrc.js, but that was over a year ago. I concur that in general it’s a bad pattern to rely on
propTypes
.This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.