javascript reactjs中状态变化的监听器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26683108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Listener for state changes in reactjs
提问by Hamza
I have a component with a couple of input fields that updates the state of the component using the valueLink={this.linkState('foo')}
facility provided by React.addons.LinkedStateMixin
.
我有一对夫妇,更新使用该组件的状态输入字段的组件valueLink={this.linkState('foo')}
提供的设施React.addons.LinkedStateMixin
。
Prior to this I was using the onChange
handler to communicate the changes back to the server using a websocket connection, so I was wondering if I could replicate this behaviour somewhat and post the changes in the state back using a "state change listener" of some sorts?
在此之前,我使用onChange
处理程序使用 websocket 连接将更改传送回服务器,所以我想知道是否可以复制这种行为并使用某种“状态更改侦听器”将状态更改发布回?
Thanks.
谢谢。
回答by Hamza
Looks like the method I am looking for is componentDidUpdate()
看起来我正在寻找的方法是componentDidUpdate()