Created
October 25, 2020 15:01
-
-
Save misss-popcorn/86ae5d4681b7877df251c57ca5dcf23f to your computer and use it in GitHub Desktop.
local state management using class in React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import "../../App.css"; | |
export class Class extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
name: "" | |
}; | |
this.handleChange = this.handleChange.bind(this); | |
} | |
handleChange(e) { | |
this.setState({name: e.target.value}); | |
} | |
render() { | |
return ( | |
<span className="Left"> | |
<p>Class Component</p> | |
<input value={this.state.name} onChange={this.handleChange}></input> | |
</span> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment