How to use GET API in ReactJS || ReactNative ||

 



import React from "react";
import { useNavigate } from "react-router";
import axios from "axios";
import { useEffect, useState } from "react";
import Navbar from "../comp/navbar";
const Help = () => {
  const navigation = useNavigate();

  const [databs, setDatabs] = useState([]);
  useEffect(() => {
    axios
      .get("https://jsonplaceholder.typicode.com/posts")
      .then((res) => {
        setDatabs(res.data);
      })
      .catch((err) => {
        console.log(err);
      });
  }, []);
  return (
    <div className="about">
      <Navbar />
      <table className="table">
        <tr className="tr">
          <th>UserId</th>
          <th>Id</th>
          <th>Title</th>
          <th>Body</th>
        </tr>

        {databs.map((item, key) => {
          return (
            <tr key={key}>
              <td className="td">
                {" "}
                <p>{item.id}</p>{" "}
              </td>
              <td className="td">
                {" "}
                <p>{item.userId}</p>{" "}
              </td>
              <td className="td">
                {" "}
                <p>{item.title}</p>
              </td>
              <td className="td">
                {" "}
                <p>{item.body}</p>
              </td>
            </tr>
          );
        })}
      </table>
    </div>
  );
};
export default Help;



App.css

.App {
  width: 100%;
  height: 100%;
}
h1 {
  color: #000;
}

.span {
  background-image: url(/src/images/13.jpg);
  background-size: cover;
  height: 100vh;
  width: 10vw;
}

.Box {
  display: flex;
  flex-direction: column;
  width: 30%;
  margin-left: 60%;
  border: 2px solid rgb(202, 192, 192);
  border-radius: 12px;
  box-shadow: 1px 3px 1px #9e9e9e;
  height: 80%;
  padding: 10px;
  text-align: center;
  position: absolute;
  background-size: cover;
  margin-top: 50px;
  background-image: url(/src/images/15.jpg);
}
.Box:hover {
  box-shadow: 0 8px 16px 0 slategrey;
}

.Box1 {
  background-image: url(/src/images/logo.png);
  background-size: cover;
  width: 160px;
  height: 150px;
  margin-left: 5%;
  position: absolute;
  margin-top: 5%;
}
.Box2 {
  position: absolute;
  margin-top: 18%;
  margin-left: 5%;
}
.text1 {
  color: aliceblue;
  font-size: large;
}
.par {
  color: rgb(35, 204, 30);
}
.par:hover {
  color: rgb(51, 136, 48);
}

.Avatar {
  margin: auto;
}
.signup {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 420px;
  border: 2px solid rgb(235, 221, 221);
  border-radius: 15px;
  box-shadow: 1px 3px 4px #9e9e9e;
  margin-top: 5%;
  position: absolute;
  background-color: blanchedalmond;
  margin-left: 35%;
}
.butt {
  text-align: center;
  margin-bottom: 20px;
}
.Box3 {
  background-image: url(/src/images/logo.png);
  background-size: cover;
  width: 160px;
  height: 150px;
  margin-left: 5%;
  position: absolute;
  margin-top: 5%;
}

.span1 {
  background-image: url(/src/images/13.jpg);
  background-size: cover;
  height: 100vh;
  width: 100vw;
}
.form {
  width: 30%;
  margin-left: 65%;
  border: 2px solid rgb(202, 192, 192);
  border-radius: 12px;
  box-shadow: 1px 3px 1px #9e9e9e;
  height: 80%;
  position: absolute;
  background-size: cover;
  margin-top: 50px;
  background-image: url(/src/images/12.jpeg);
}
.text2 {
  color: #fff;
  font-size: medium;
}
.head {
  height: auto;
}
.footer {
  position: relative;
  margin-top: 110px;
  width: 100vw;
  height: 60vh;
}
.h1 {
  text-align: center;
}
.table {
  border: 2px solid rgb(10, 10, 10);
}
.td {
  border: 2px solid rgb(10, 10, 10);
}


Post a Comment

0 Comments