[英]Trying to change state while using a function in React.js
I'm trying to change state of my component while calling of a function. 我正在尝试在调用函数时更改组件的状态。 the function is suppose to take some data and push it in the state 该函数假定要获取一些数据并将其推入状态
StartChat: function (e) {
e.preventDefault();
var data = this.props.FirstName;
this.setState({ChatBoxMembers:data});
}
Calling the above function with and onClick function I've check the value gets stored in variable 'data' but the state 'ChatBoxMembers' doesn't change and end up with the error ChatBoxMembers is not defined
what am I doing wrong here? 用onClick函数调用上面的函数,我已经检查了值是否存储在变量'data'中,但是状态'ChatBoxMembers'并没有改变并且最终出现了ChatBoxMembers is not defined
错误,这是我在做什么错呢?
For starters, you have declared ChatBoxMembers
as []
but you are assigning linear data to it. 对于初学者,您已经将ChatBoxMembers
声明为[]
但您正在为其分配线性数据。 Need to have access to code for ChatBoxMembers is not defined
error. 需要访问ChatBoxMembers is not defined
代码ChatBoxMembers is not defined
错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.