Skip to content

Instantly share code, notes, and snippets.

@stolinski
Created February 19, 2019 20:18
Show Gist options
  • Save stolinski/5362d2914bc6461e2a8d06595400bd37 to your computer and use it in GitHub Desktop.
Save stolinski/5362d2914bc6461e2a8d06595400bd37 to your computer and use it in GitHub Desktop.
Refactor For Hooks Course
import React, { Component } from "react";
export default class Refactor extends Component {
state = {
isToggled: false
};
toggle = () => {
this.setState(state => {
return { isToggled: !state.isToggled };
});
};
render() {
return (
<div>
<button onClick={this.toggle}>Toggle</button>
{this.state.isToggled && <h2>Hello!</h2>}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment