Skip to content

Passing a React class as a prop no longer works in 0.13.* #3652

Closed
@ezequiel

Description

@ezequiel

Hi,

I'm trying to run the following code using the latest version of React:

var MyComponent = React.createClass({
    render: function() {
        return (
            <div>
                <this.props.template 
                    data='test'
                />
            </div>
        );
    }
});

var App = React.createClass({
    render: function() {
        return (
            <MyComponent 
                template={this.template}
            />
        );
    },

    template: React.createClass({
        render: function() {
            return <p>{this.props.data}</p>;
        }
    })
});

React.render(<App />,  document.body);

However, an error is thrown once the code is ran: "Uncaught TypeError: Cannot read property 'mountComponent' of undefined"

The above code functions as expected in React 0.12.2. Someone figured out this is due to a change in the way React 0.13.* classes autobinds all of its methods. Therefore, changing App's render method to this fixes the issue:

    render: function() {
        var tmpl = React.createClass({
            render: function() {
                return <p>{this.props.data}</p>;
            }
        });

        return (
            <MyComponent 
                template={tmpl}
            />
        );
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions