像這則例子,
var React = require('react');
var ReactDOM = require('react-dom');
var Child = require('./Child');
var Parent = React.createClass({
getInitialState: function () {
return { name: 'Frarthur' };
},
changeName: function (newName) {
this.setState({
name: newName
});
},
render: function () {
return (
<Child
name={this.state.name}
onChange={this.changeName} />
);
}
});
//因為需要定義作用中function,所以一定要記得加上this啊~~
ReactDOM.render(
<Parent />,
document.getElementById('app')
);
沒有留言:
張貼留言