Difference between revisions of "Event Handling in React"
From Logic Wiki
(Created page with "Category:React in the class switchNameHandler = () => { console.log('clicked'); } render(){ return ( <button onClick={this.switchNameHandler}>Swit...") |
|||
| Line 6: | Line 6: | ||
console.log('clicked'); | console.log('clicked'); | ||
} | } | ||
| − | |||
render(){ | render(){ | ||
return ( | return ( | ||
<button onClick={this.switchNameHandler}>Switch Name</button> | <button onClick={this.switchNameHandler}>Switch Name</button> | ||
| + | |||
| + | === setState === | ||
| + | |||
| + | switchNameHandler = () => { | ||
| + | this.setState({person:{name:'aaa'}); | ||
| + | } | ||
| + | [[File:State.JPG]] | ||
Revision as of 15:29, 12 July 2018
in the class
switchNameHandler = () => {
console.log('clicked');
}
render(){
return (
<button onClick={this.switchNameHandler}>Switch Name</button>
setState
switchNameHandler = () => {
this.setState({person:{name:'aaa'});
}