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
})
);
};