Skip to content

Instantly share code, notes, and snippets.

@oshell
Created November 17, 2019 20:03
Show Gist options
  • Save oshell/edc14611adc1a72f599574c26727e98d to your computer and use it in GitHub Desktop.
Save oshell/edc14611adc1a72f599574c26727e98d to your computer and use it in GitHub Desktop.
stateful functional component
import React, { useState } from 'react';
import './App.css';
function App() {
const [color, changeColor] = useState('blue');
return (
<div className="App">
<button onClick={changeColor.bind(null, 'blue')}>blue</button>
<button onClick={changeColor.bind(null, 'green')}>green</button>
<button onClick={changeColor.bind(null, 'red')}>red</button>
<div className={`box ${color}`}>
Lorem Ipsum
</div>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment