Skip to content

Instantly share code, notes, and snippets.

@misss-popcorn
Created October 25, 2020 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misss-popcorn/86ae5d4681b7877df251c57ca5dcf23f to your computer and use it in GitHub Desktop.
Save misss-popcorn/86ae5d4681b7877df251c57ca5dcf23f to your computer and use it in GitHub Desktop.
local state management using class in React
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