react 如何组合


例如现在有Button和 Nav两个类
能不能实现这样


 var Button, Nav; //实现省略
React.render(
    <Nav> 
        <Button></Button>
    </Nav>
, docuememt.getElementById('div'))

这样 Nav类该怎么写

reactjs react.js

deoxys 9 years, 7 months ago

var Nav = React.createClass({


 render:function(){
    <div>...</div>
}

})

Felidae answered 9 years, 7 months ago

Nav.jsx


 var Nav = React.createClass({
  render: function() {
    return (
      <div className="commentBox">
        Hello, world! I am a CommentBox.
        { this.props.children }
      </div>
    );
  }
});

index.jsx


 React.render(
        <Nav>
            <button>BUTTON</button>
        </Nav>,
        document.getElementById('div')
      );

plunker

游戏X黑魔导 answered 9 years, 7 months ago

Your Answer