How to make multiple API calls within React Native and Reflux
Web Technologies
Web Development
2 years ago
5
Star Rating
1
Rating
_x000D_
_x000D_
I am following Indrik Lasn's React/Reflux/Thunk tutorial in React Native Training and having a hard time editing the code to allow for chained API calls.
Tutorial Link: https://medium.com/react-native-training/learn-how-to-build-a-rn-redux-cryptocurrency-app-chapter-iii-a454dda156b
How do I chain multiple API calls from coinmarketcap.com's API?
This is the code I thought would work. Developer tools shows the data is coming in for the 2 API calls but once the 2nd API loads into the browser, it replaces the data from the 1st API data within the view?
import axios from 'axios';
import { apiBaseURL } from './../Utils/Constants';
import {
FETCHING_COIN_DATA,
FETCHING_COIN_DATA_SUCCESS,
FETCHING_COIN_DATA_FAIL
} from './../Utils/ActionTypes';
export default function FetchCoinData() {
return dispatch => {
dispatch({ type: FETCHING_COIN_DATA })
axios.get(`${apiBaseURL}/v1/ticker/bitcoin`)
.then(res => dispatch({ type: FETCHING_COIN_DATA_SUCCESS, payload: res.data }))
.then(() => axios.get(`${apiBaseURL}/v1/ticker/litecoin`))
.then(res => dispatch({ type: FETCHING_COIN_DATA_SUCCESS, payload: res.data }))
.catch(err => {
dispatch({ type: FETCHING_COIN_DATA_FAIL, payload: err.data })
});
}
}
Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Take Quiz To Earn Credits!
Turn Your Knowledge into Earnings.