Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

api dfetch data in 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
Comment

PREVIOUS NEXT
Code Example
Javascript :: date change 
Javascript :: outlet context remix js 
Javascript :: dynamically create html table in javascript 
Javascript :: JavaScript URL Parse including pathname 
Javascript :: Example of Logical AND assignment operator in es12 
Javascript :: Renaming props in react 
Javascript :: Default function arguments in ES6 
Javascript :: on click disable esc button using jquery 
Javascript :: hover over class apply to subclass 
Javascript :: json_populate_recordset 
Javascript :: svg documentation 
Javascript :: get text 
Javascript :: telegram web app js 
Javascript :: salesforce js merge object 
Javascript :: function last character return 
Javascript :: programmatically change mongoose schema enum values 
Javascript :: how to change elemen size in js when custom page width changed 
Javascript :: node app not visible in browser aws ec2 
Javascript :: alpinejs checknox selectAll 
Javascript :: e.stopPropagation() is not working as expected 
Javascript :: joomla add javascript 
Javascript :: { "rules": { ".read": true, ".write": true } } 
Javascript :: javascript to prevent method POST from realoading 
Javascript :: sum the two first minimum numbers in an array 
Javascript :: Render raw html in response with Express 
Javascript :: how to create custom callback function in javascript 
Javascript :: datetimepicker how to display only current motnh 
Javascript :: javascript categories input object example 
Javascript :: asyncGenerator 
Javascript :: my env.local file not working in my react app usind mac 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =