I’m having an issue making axios asynchronous due to a Unexpected reserved word ‘await’ error. Here’s my code:
useEffect(() => { APIcall(); }, []); const APIcall = async () => { //form data… const res = await axios .post(`url`, formData, { headers: { “Content-Type”: “application/x-www-form-urlencoded”, “X-CSRFToken”: location.state.token, }, withCredentials: true, // withCredentials: true to make cors requests }) };
I checked out this article here but it doesn’t seem to work. I tried adding async inside of useEffect which also didn’t change the result. I’m wondering if there’s something obvious I’m messing up?
submitted by /u/charles_atlas_12
[link] [comments]