Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- App.jsx
- import React, { useReducer, useState } from 'react'
- import Nomes from './Nomes'
- function App(){
- const [nome, setNome] = useState('')
- const [nomes, setNomes] = useState([])
- function salvarNome(){
- setNomes(tmp => [...tmp, nome])
- }
- return (
- <>
- <h1>React Unique ID</h1>
- <hr />
- <input type="text" onChange={e => setNome(e.target.value) } value={nome} />
- <button onClick={salvarNome}>Salvar nome</button>
- <Nomes nomes={nomes}></Nomes>
- </>
- )
- }
- export default App
- ------------------------------------------------------------------------------------
- Nomes.jsx
- import React from 'react'
- import { v4 as uuid } from 'uuid'
- export default function Nomes({nomes}){
- return (
- <>
- {nomes.map(nome => <p key={uuid()}>{nome}</p>)}
- </>
- )
- }
Advertisement
Add Comment
Please, Sign In to add comment