Axios with useEffect

PHOTO EMBED

Tue Jun 14 2022 16:23:11 GMT+0000 (Coordinated Universal Time)

Saved by @jen_magpantay #javascript #react.js

// create services folder and api file
import axios from "axios";

export const api = axios.create({
  baseURL: " http://localhost:3333",
});

// on the page where the useEffect is located
import { api } from "./services/api";

 useEffect(() => {
    async function getData() {
      const response = await api.get("/episodes");
      setData(response.data);
    }
    getData();
  }, []);
content_copyCOPY