Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
axios instance not working as expected in React.js

I have a component called Login.js There I import Axios libray normal way and it works like this.

import axios from 'axios';

const data = await axios.post('/user/login/', {
        email: e.email,
        password: e.password,
      });

enter image description here

Getting 404 is fine because I didn't set any base URL for the Axios. Please note all the requests, response headers here.

Then I try to created Axios instance inside a lib folder and import it like this

/src/lib/axios.js

import axios from "axios";

const baseUrl = process.env.REACT_APP_BE_URL;

const axiosInstance = axios.create({
  baseURL: baseUrl,
});

export default axiosInstance;

I import this instance instead of normal Axios import.

import axios from 'libs/axios';

Now I see the request like this a lot of properties missing in the request and this isn't working enter image description here

How do I fix this?

Any help thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const axiosInstance = axios.create({
  baseURL: baseUrl,
  // here you can pass other options to axios instance.
});

Or you can use request interceptors with axios

axiosInstance.interceptors.request.use(
  config => {
    config.headers['X-Header'] = true


    return config
  },
  error => {
    console.log(error) // for debug
  }
)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!