NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 49

fetch API | GET method

Helpful for get data from another server. its JSON formate.

Here's is the Code !!

import React,{useEffect,useState} from "react"
function App() {
  const [users,setUser]=useState([])
  useEffect(()=>{
    fetch("http://localhost:4000/todo").then((result)=>{
      result.json().then((resp)=>{
        // console.warn(resp)
        setUser(resp)
      })
    })
  },[])
  console.warn(users)
  return (
    <div className="App">
      <h1>Get API Call </h1>
      <table border="1">
       <tbody>
       <tr>
          <td>ID</td>
          <td>Name</td>
          <td>Email</td>
          <td>Mobile</td>
        </tr>
        {
          users.map((item,i)=>
            <tr key={i}>
            <td>{item.userId}</td>
          <td>{item.name}</td>
          <td>{item.email}</td>
            <td>{item.mobile}</td>
          </tr>
          )
        }
       </tbody>
      </table>
    </div>
  );
}
export default App;

Chapter 48

Protected Route

Previous chapter

Chapter 50

POST Method in Rest API

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex