react 구성 요소 간의 매개 변수 전달

3840 단어 jsReact
const MessageBox = React.createClass({
            getInitialState:function() {
                return {
                    title: 'props ',
                    messages: ['messages1','messages2','messages3','messages4']
                }
            },
            render: function () {
                return (
                    

1

{this.state.title}

this.state.messages}/>
) } }); const SubMessageBox = React.createClass({ propTypes: { // messages: React.PropTypes.array.isRequired }, getDefaultProps: function(){ return { messages: [' message, , , , '] } }, render:function() { {/* let messages = []; this.props.messages.forEach(function(msg,index) { console.log(msg); messages.push(msg) }); console.log(this.props.messages)*/} return(

2

{this.props.messages}

this.props.messages} />
) } }) const Footer = React.createClass({ render:function() { let messages = []; this.props.messages.forEach(function(msg,index) { msg += index messages.push(msg) }); return (

3

{messages}

) } }) const MessageBoxObj = React.render( , document.getElementById('app'), function() { console.log(' '); } );

좋은 웹페이지 즐겨찾기