最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReactJs. Get children component - Stack Overflow

programmeradmin1浏览0评论

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>
        );
    }
});

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>
        );
    }
});
Share Improve this question asked Feb 20, 2016 at 21:57 AlexandrAlexandr 8871 gold badge8 silver badges16 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

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

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

评论列表(0)

  1. 暂无评论