Skip to content

Instantly share code, notes, and snippets.

@luizomf
Last active August 20, 2024 19:47
Show Gist options
  • Save luizomf/de63d9acd0c7f45f801749355bfb400e to your computer and use it in GitHub Desktop.
Save luizomf/de63d9acd0c7f45f801749355bfb400e to your computer and use it in GitHub Desktop.
Exemplo de useState - Curso React.
import logo from './logo.svg';
import './App.css';
import { useState } from 'react';
function App() {
const [reverse, setReverse] = useState(false);
const [counter, setCounter] = useState(0);
const reverseClass = reverse ? 'reverse' : '';
const handleClick = () => {
setReverse(!reverse);
};
const handleIncrement = () => {
setCounter(counter + 1);
};
return (
<div className="App">
<header className="App-header">
<img src={logo} className={`App-logo ${reverseClass}`} alt="logo" />
<h1>Contador: {counter}</h1>
<p>
<button type="button" onClick={handleClick}>
Reverse {reverseClass}
</button>
</p>
<p>
<button type="button" onClick={handleIncrement}>
Increment {counter}
</button>
</p>
</header>
</div>
);
}
export default App;
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
.reverse {
animation: App-logo-spin-reverse infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@keyframes App-logo-spin-reverse {
from {
transform: rotate(360deg);
}
to {
transform: rotate(0deg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment