babel-plugin-transform-react-remove-prop-types icon indicating copy to clipboard operation
babel-plugin-transform-react-remove-prop-types copied to clipboard

Issue when used with `createReactClass`

Open carystanley opened this issue 6 years ago • 1 comments

I found that the plugin had issues when used with createReactClass

example:

var SelectBox = createReactClass({

    propTypes: {	
        value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),	
        selectId: PropTypes.string.isRequired,	
        fullwidth: PropTypes.bool.isRequired	
    },
...
});

Seems to somewhat work on createReactClass components as long as the the propTypes declaration is not two deep like a PropTypes.string.isRequired or as long as functions are not used like: PropTypes.oneOfType(), PropTypes.arrayOf(), or PropTypes.shape(). Almost like PropTypes is being replaced with an empty object.

carystanley avatar Oct 09 '19 17:10 carystanley

Workaround for users experience this is to move propTypes declaration outside of createReactClass:

example:

var SelectBox = createReactClass({
...
});

SelectBox.propTypes = {	
    value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),	
    selectId: PropTypes.string.isRequired,	
    fullwidth: PropTypes.bool.isRequired	
};

carystanley avatar Oct 09 '19 17:10 carystanley