Anwar Isied
Anwar Isied

Reputation: 19

Call Axios with componentDidMount get request is in infinite loop

Axios starts making the GET request and never stops anymore when I add the following code to the component data. No changing on the state or no calling the setState method.

componentDidMount() {
        axios('https://api.npms.io/v2/search?q=react')
            .then(response => {
                alert(response.data);
            });
    }

Upvotes: 1

Views: 147

Answers (2)

Anwar Isied
Anwar Isied

Reputation: 19

The problem was from using axios instance and NLog.

Upvotes: 0

Viet
Viet

Reputation: 12777

I think you should use axios.get(), not axios():

        axios.get('https://api.npms.io/v2/search?q=react')
            .then(response => {
                alert(response.data);
            });

Upvotes: 1

Related Questions