reactjs - React updating state within the same component -


i new react, thought setting state re-render react component. did miss here, text not displayed until call this.forceupdate().

export default class hello extends react.component {   constructor(props){     super(props);     this.state = { value: ''};     this.handlechange = this.handlechange.bind(this);      }    render() {     return (         <div>             <input type="text" onchange={this.handlechange}   />             <p> entered {this.state.value} </p>         </div>     );   }     handlechange(event){           this.state = { value: event.target.value };          this.forceupdate();   } } 

you should call .setstate method instead of assign new value this.state

handlechange(event){         this.setstate({ value: event.target.value }) } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -