var AnimationExample=React.createClass({
getInitialState:function(){
return {
position:0
}
},
animationFun:function(){
if(this.state.positionThis is animate!
)
}
});
ReactDOM.render(
,
document.getElementById('animationContent')
);
ReactDOM.render(
,document.getElementById('animationContent')
);
这是一个简单的js模拟动画,我的疑问是为什么最后要render两次,而render一次不行呢
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我觉得用React写动画还是不用
setState吧,因为一般来说你已经确切的知道要修改哪些属性值,而setState还要去diff整个state,感觉会影响效率。因为列出的component会根据
position属性的变化而更新,第一次render时compoent没有props.position,第二次render后props.position的值为100。