Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created May 6, 2020 09:09
Show Gist options
  • Save Ratstail91/0746c0da5215a490b2fcc1c44407ae0a to your computer and use it in GitHub Desktop.
Save Ratstail91/0746c0da5215a490b2fcc1c44407ae0a to your computer and use it in GitHub Desktop.
I didn't run this, but it should be mostly correct.
import React from 'react';
import ReactDOM from 'react-dom';
class ExampleClass extends React.Component {
constructor(props) {
super(props);
this.state = {
isClicked: false;
};
}
handleClick() {
this.setState({
isClicked: !this.state.isClicked
});
}
render() {
return (
<div className='container'>
<div id='someElement' className={this.state.isClicked ? 'clicked' : ''}>
I'm an element.
</div>
<button id='someButton' onClick={this.handleClick}>
Click me!
</button>
</div>
);
}
};
ReactDOM.render(
<ExampleClass />,
document.getElementById('content')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment