Fetching data from API in JavaScript
up vote
3
down vote
favorite
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 }) ); }; ...