axios get params does not inherit the params in create

Viewed 1708

Playing around with youtube api and reactjs

I am calling youtube api. Recently noticed there is create in axios so I wanted to use it but somehow params kept on overwritten

What am I doing wrong here?

I have a file named youtube.api

import axios from 'axios';

export default axios.create({
    baseURL: 'https://www.googleapis.com/youtube/v3',
    params: {
        part: 'snippet',
        key: 'blahkey',
    }
});

then inside my react handleOnSubmit import youtube from '../apis/youtube';

handleOnSubmit = async (e) => {
    e.preventDefault();
    console.log(this.state.query);
    const response = await youtube.get('/search', {
        params: { q: this.state.query }
    });

    console.log(response, 'response');

};

console.log(response, 'response');

I get an error of https://www.googleapis.com/youtube/v3/search?q=book 400

the params of part and key are missing from the url though.

Can someone please give me a hand?

Thanks in advance

2 Answers

I found out that this might be due to new version issue. I am using "axios": "^0.19.0" which is causing this issue.

I downgrade it to "axios": "^0.18.0" and "axios": "^0.18.1", both worked fine

P.S. I went through their issue tickets on github and this was posted 6 days ago https://github.com/axios/axios/issues/2190

Downgrading the version of Axios helped me.

To downgrade the version

kill the server and run

npm install --save axios@0.18.1

this will downgrade the version of Axios from latest to 0.18.1

Related