Skip to content

Instantly share code, notes, and snippets.

@juniormartinxo
Created November 30, 2022 20:54
Show Gist options
  • Save juniormartinxo/aad258ab70e139fcba7111387a574dfb to your computer and use it in GitHub Desktop.
Save juniormartinxo/aad258ab70e139fcba7111387a574dfb to your computer and use it in GitHub Desktop.

Apenas um exemplo de código para meu garoto Moisés! 🥰

import { useState } from 'react'
import reactLogo from './assets/react.svg'
import './App.css'

function App() {
  const [count, setCount] = useState(0)
  const [name, setName] = useState('Digite seu nome, por favor!')
  const [valueInput, setValueInput] = useState('')

  const handle = e => {
    e.preventDefault()

    if (e.key === 'Enter') {
      setName(`🤙 Legal que seu nome é ${e.target.value}`)
      setValueInput('')
    }
  }

  return (
    <div className='App'>
      <h1>{name}</h1>
      <form action='#'>
        <input
          type='text'
          id='textName'
          className='txtName'
          onKeyUp={e => handle(e)}
          value={valueInput}
          onChange={e => setValueInput(e.target.value)}
        />
      </form>
    </div>
  )
}

export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment