Dados da API DFetch em ReactJs
import React, { useState } from "react"
2
3const SearchUser = () => {
4 const [users, setUsers] = useState([])
5
6 const fetchData = e => {
7 const query = e.target.value
8 fetch(`https://jsonplaceholder.typicode.com/users?q=${query}`)
9 .then(response => {
10 return response.json()
11 })
12 .then(data => {
13 setUsers(data)
14 })
15 }
16
17 return (
18 <div>
19 <input onChange={fetchData} label="Search User" />
20 {users.length > 0 && (
21 <ul>
22 {users.map(user => (
23 <li key={user.id}>{user.name}</li>
24 ))}
25 </ul>
26 )}
27 </div>
28 )
29}
30
31export default SearchUser
Hetul Patel