基于此链接http://reactjs.cn/react/tips/expose-component-functions.html上的示例,我一直在尝试简化代码以更好地理解公开的方法,所以我得到了以下内容,它没有t 工作,错误是“未捕获的类型错误:无法读取未定义的属性 'animate'”,我真的不知道原因:
var Todo = React.createClass({
render: function() {
return <div></div>;
},
//this component will be accessed by the parent through the `ref` attribute
animate: function() {
console.log('Pretend is animating');
}
});
var Todos = React.createClass({
render: function() {
return (
<div>
<Todo ref='hello' />
{this.refs.hello.animate()}
</div>
);
}
});
ReactDOM.render(<Todos />, app);