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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:18:36  来源:igfitidea点击:

Listener for state changes in reactjs

javascriptjavascript-eventsreactjs

提问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 onChangehandler 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()