Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin tries to wrap PropTypes.shape #25

Closed
mmakarin opened this issue Feb 4, 2016 · 4 comments
Closed

Plugin tries to wrap PropTypes.shape #25

mmakarin opened this issue Feb 4, 2016 · 4 comments

Comments

@mmakarin
Copy link

mmakarin commented Feb 4, 2016

Source:

import React, { PropTypes } from "react";
import { PureComponent } from "react-pure-render";

export default class Table extends PureComponent {
    static propTypes = {
        columns: PropTypes.arrayOf(PropTypes.shape({
            title: PropTypes.string,
            render: PropTypes.func
        })),
        data: PropTypes.array
    };

    ...

Output

var Table = _wrapComponent("Table")((_temp = _class = function (_PureComponent) {
    _inherits(Table, _PureComponent);

    function Table() {
        _classCallCheck(this, Table);

        return _possibleConstructorReturn(this, Object.getPrototypeOf(Table).apply(this, arguments));
    }

    _createClass(Table, [{
        key: "render",
        value: function render() {
             ...
        }
    }]);

    return Table;
}(_reactPureRender.PureComponent), _class.propTypes = {
    columns: _react2.PropTypes.arrayOf(_wrapComponent("_component")(_react2.PropTypes.shape({
        title: _react2.PropTypes.string,
        render: _react2.PropTypes.func
    }))),
    data: _react2.PropTypes.array
}, _temp));

And it fails on the line

var originalRender = ReactClass.prototype.render;

with the following error because PropTypes.Shape.prototype.render is undefined

Uncaught TypeError: Cannot read property 'render' of undefined
wrapToCatchErrors @ index.js:30(anonymous function)
@ Table.js:65(anonymous function)
@ Table.js:151(anonymous function) 
...
@mmakarin
Copy link
Author

mmakarin commented Feb 9, 2016

@gaearon
Copy link
Owner

gaearon commented Feb 15, 2016

This doesn’t appear to have anything to do with gaearon/babel-plugin-react-transform#26.

gaearon/babel-plugin-react-transform#26 is a feature request for wrapping exports.

What you see is a bug in Babel plugin where it wraps React.whatever instead of strictly React.createClass. I filed it as gaearon/babel-plugin-react-transform#84.

A test and a fix are welcome!

@gaearon gaearon closed this as completed Feb 15, 2016
@gaearon
Copy link
Owner

gaearon commented Feb 18, 2016

I think I know what the problem is.
Fix is welcome: gaearon/babel-plugin-react-transform#84 (comment).

@gaearon
Copy link
Owner

gaearon commented Mar 4, 2016

Should be fixed in 2.0.1.

@gaearon gaearon reopened this Mar 4, 2016
@gaearon gaearon closed this as completed Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants