Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackCodeReview/status/1030696089370935296
Bumped by Community user
edited title
Link

Fetching data from API in JavsScriptJavaScript

deleted 1 character in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Fetching data from apiAPI in javascriptJavsScript

i'mI'm using axiosAxios to fetch data from apian API, and don't know if this is the best way to deal with APIs in ReactjsReactJS or not, So. I want to know if anyone can suggest edits or something to make the code more efficient.

here's my code: api.jsapi.js

import axios from 'axios';

export const APIendpoint = axios.create({
    baseURL: 'https://1eb19101-0790-406f-90e0-ee35a2ff2d1f.mock.pstmn.io',
    timeout: 2000
});

matchesAction.jsmatchesAction.js

import {FETCH_MATCHES} from './actionTypes';
import {APIendpoint} from '../api/api';

export const fetchMatches = () => dispatch => {
    const matchInstance = APIendpoint.get('/matches');
    matchInstance.then(response =>
        dispatch({
            type: FETCH_MATCHES,
            payload: response.data
        })
    );
};

Fetching data from api in javascript

i'm using axios to fetch data from api, and don't know if this is the best way to deal with APIs in Reactjs or not, So if anyone can suggest edits or something make the code more efficient.

here's my code: api.js

import axios from 'axios';

export const APIendpoint = axios.create({
    baseURL: 'https://1eb19101-0790-406f-90e0-ee35a2ff2d1f.mock.pstmn.io',
    timeout: 2000
});

matchesAction.js

import {FETCH_MATCHES} from './actionTypes';
import {APIendpoint} from '../api/api';

export const fetchMatches = () => dispatch => {
    const matchInstance = APIendpoint.get('/matches');
    matchInstance.then(response =>
        dispatch({
            type: FETCH_MATCHES,
            payload: response.data
        })
    );
};

Fetching data from API in JavsScript

I'm using Axios to fetch data from an API, and don't know if this is the best way to deal with APIs in ReactJS or not. I want to know if anyone can suggest edits or something to make the code more efficient.

api.js

import axios from 'axios';

export const APIendpoint = axios.create({
    baseURL: 'https://1eb19101-0790-406f-90e0-ee35a2ff2d1f.mock.pstmn.io',
    timeout: 2000
});

matchesAction.js

import {FETCH_MATCHES} from './actionTypes';
import {APIendpoint} from '../api/api';

export const fetchMatches = () => dispatch => {
    const matchInstance = APIendpoint.get('/matches');
    matchInstance.then(response =>
        dispatch({
            type: FETCH_MATCHES,
            payload: response.data
        })
    );
};
Source Link

Fetching data from api in javascript

i'm using axios to fetch data from api, and don't know if this is the best way to deal with APIs in Reactjs or not, So if anyone can suggest edits or something make the code more efficient.

here's my code: api.js

import axios from 'axios';

export const APIendpoint = axios.create({
    baseURL: 'https://1eb19101-0790-406f-90e0-ee35a2ff2d1f.mock.pstmn.io',
    timeout: 2000
});

matchesAction.js

import {FETCH_MATCHES} from './actionTypes';
import {APIendpoint} from '../api/api';

export const fetchMatches = () => dispatch => {
    const matchInstance = APIendpoint.get('/matches');
    matchInstance.then(response =>
        dispatch({
            type: FETCH_MATCHES,
            payload: response.data
        })
    );
};