- I am doing a join in the axios call.
- since doing two different api calls.
- for performance is this the good way.
- or do I need to use async await and then do join.
- providing code snippet below
export function getSearch(value) {
console.log('-- getSearch value', value);
return dispatch => {
if (value.length) {
if (typeof this._source !== 'undefined') {
this._source.cancel('Operation canceled due to new request');
}
this._source = axios.CancelToken.source();
return axios
.get(
`http://localhost:787878/hold/search?mode=Smart&value=${value}`,
{
cancelToken: this._source.token,
}
)
.then(response => {
console.log('search response.data-->', response.data);
let values = response.data.map(filterSearch => {
if (filterSearch.playerIDs) {
console.log(
'search response.data playerIDs',
filterSearch.playerIDs[0]
);
return filterSearch.playerIDs[0].number + ',';
}
});
console.log(
'search response.data join--->',
values.join('')
);
axios
.get(
`http://localhost:787878/hold/animalworldCardList/?playerID=${values.join(
''
)}&isHistory=false`,
//localhost:787878/hold/ce-affiliation/?animalPimsId=${animalPimsId}&isHistory=${isHistory}`,
{
cancelToken: this._source.token,
}
)
.then(responseplayerIDs => {
console.log(
'search response.data -->',
responseplayerIDs
);
dispatch({
type: ANIMAL_SEARCH_DATA,
payload: {
animalSearch: response.data,
playerIDs:
responseplayerIDs.data.animalsInfo,
},
});
// callBack(response);
})
.catch(error => {
if (axios.isCancel(error)) {
console.log(
'-- Request canceled',
error.message
);
} else {
console.log('-- Error', error.message);
}
});
})
.catch(error => {
if (axios.isCancel(error)) {
console.log('-- Request canceled', error.message);
} else {
console.log('-- Error', error.message);
}
});
} else {
dispatch({
type: ANIMAL_SEARCH_DATA,
payload: [],
});
}
};
}
{values.join(
\$\endgroup\$