简体   繁体   中英

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?

For starters, you have declared ChatBoxMembers as [] but you are assigning linear data to it. Need to have access to code for ChatBoxMembers is not defined error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM