Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from 'react'
- export default function App(){
- const [player, setPlayer] = useState({
- name: 'Ilan',
- score: 0
- })
- function alterar(){
- setPlayer(pa => {
- return {
- ...pa,
- score: pa.score + 1
- }
- })
- }
- return (
- <>
- <h1>React Hooks - useStates</h1>
- <hr/>
- <h3>Nome: {player.name}</h3>
- <h3>Nome: {player.score}</h3>
- <button onClick={alterar}>Alterar a pontuação</button>
- </>
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment