Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

javascript - Facing issue on onChange function in React

facing issue during getting target value in this case i can't be able to add the value. Whereas with same code some other places it is working fine. Please explain about expected scanarios. here is my code

<input type="text" value={filterEventValue} name='filterEventValue' autocomplete="off" onChange={ this.filterEventUsers} />


 filterEventUsers = (e) => {
        console.log("e ::", e.target);
    }

When I am typing inside text field key is is not being typed inside field. outPut: enter image description here

question from:https://stackoverflow.com/questions/65917565/facing-issue-on-onchange-function-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you should keep the input value in the state, and update it when typing:

constructor(props) {
  super(props);
  this.state = { filterEventValue: '' };
}

filterEventUsers = (e) => {
  console.log("e ::", e.target);
  this.setState({ filterEventValue: e.target.value });
}

render() {
   return (
    <input type="text" value={filterEventValue} name='filterEventValue'  
      autocomplete="off" onChange={this.filterEventUsers.bind(this)} />
   )
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...