Alexandr
Alexandr

Reputation: 887

ReactJs. Get children component

I've component wrapper for Bootstrap Panel:

var Panel = React.createClass({
    render: function () {
        return (
            <div className="panel panel-default">
                <div className="panel-heading">
                    <div className="panel-title">
                        {this.props.title}
                    </div>
                </div>
                <div className="panel-body"></div>
            </div>
        );
    }
});

How to output to "panel-body" tag "h1" and component "AvailableActions" on example what you can see below?

var PlayerActions = React.createClass({
    render: function () {
        return (
            <Panel title="Actions">
                <h1>Some description here...</h1>
                <AvailableActions></AvailableActions>
            </Panel>
        );
    }
});

Upvotes: 9

Views: 29488

Answers (2)

Oleksandr T.
Oleksandr T.

Reputation: 77482

Seems you need this.props.children

var Panel = React.createClass({
    render: function () {
        return (
            <div className="panel panel-default">
                <div className="panel-heading">
                    <div className="panel-title">
                        {this.props.title}
                    </div>
                </div>
                <div className="panel-body">{ this.props.children }</div>
            </div>
        );
    }
});

Example

Upvotes: 14

C. K. Young
C. K. Young

Reputation: 222993

<div className="panel-body">
    {this.props.children}
</div>

Upvotes: 4

Related Questions