The second useEffect block runs before the first has received any data back. This causes the second block to return an error and an empty array.
I've tried using async/await, as this has solved problems like this for me in the past. However, it doesn't seem to have an effect here.
const [session, setSession] = useState("");
const [champions, setChampions] = useState([]);
useEffect(() => {
axios.get(`http://api.paladins.com/paladinsapi.svc/createsessionJson/${devId}/${generateSignature('createsession')}/${moment.utc().format('YYYYMMDDHHmmss')}`).then((response) => {
setSession(response.data.session_id);
console.log(session);
}).catch((error) => {
console.log(error);
})
}, [])
useEffect(() => {
axios.get(`http://api.paladins.com/paladinsapi.svc/getchampionsJson/${devId}/${generateSignature('getchampions')}/${session}/${moment.utc().format('YYYYMMDDHHmmss')}/1`).then((response) => {
setChampions(response.data);
console.log(champions);
}).catch((error) => {
console.log(error);
})
}, []);
It should return an array of objects to champions, but since it doesn't receive a session id, the api call is not the correct address keeping champions as an empty array.