javascript - Animate component when state changes in React.js - Stack Overflow

I'm trying to make a small animation on HTML element when data values stored in state change. How

I'm trying to make a small animation on HTML element when data values stored in state change. How can achieve that?

How can I add a CSS class to ponent in ponentWillUpdate and remove it in ponentDidUpdate? I don't see any reference to any HTML element there.

I'm trying to make a small animation on HTML element when data values stored in state change. How can achieve that?

How can I add a CSS class to ponent in ponentWillUpdate and remove it in ponentDidUpdate? I don't see any reference to any HTML element there.

Share Improve this question edited Jun 11, 2015 at 8:42 Pete 58.5k29 gold badges130 silver badges184 bronze badges asked Jun 10, 2015 at 18:40 sunpietrosunpietro 2,0984 gold badges25 silver badges44 bronze badges 3
  • I remend to read facebook.github.io/react/docs/animation.html – Felix Kling Commented Jun 10, 2015 at 18:42
  • Or you could also simply search: stackoverflow./search?q=%5Breactjs%5D+animation – Felix Kling Commented Jun 10, 2015 at 18:55
  • I tried, but I used wrong keywords. I got only a couple of results. – sunpietro Commented Jun 10, 2015 at 21:03
Add a ment  | 

1 Answer 1

Reset to default 4

If you need to add a class to a ponent: React.findDOMNode(this).classList.add("classname");

To remove: React.findDOMNode(this).classList.remove("classname");

If you're trying to add a class in ponentWillUpdate and remove it in ponentDidUpdate, you'd need to use something like a setTimeout to notice a change. For example:

ponentWillUpdate: function() {
    React.findDOMNode(this).classList.add("class1", "class2");
},
ponentDidUpdate: function() {
    var el = React.findDOMNode(this);
    setTimeout(function(){
       el.classList.remove("class1");
    }, 1000);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300254a4621392.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信