Skip to main content

9.16 Creating And Using Axios Instances

New axios.js

axios.js
import axios from "axios";

const instance = axios.create({
baseURL: "https://jsonplaceholder.typicode.com",
});

instance.defaults.headers["Authorization"] = "AUTH TOKEN FROM INSTANCE";

// instance.interceptors.request...
export default instance;

Blog.js

Blog.js
// import axios from "axios";
import React, { Component } from "react";
import axios from "../../axios";
import FullPost from "../../components/FullPost/FullPost";
import NewPost from "../../components/NewPost/NewPost";
import Post from "../../components/Post/Post";
import "./Blog.css";

...