In my useEffect function, I'm first attempting to verify my 'auth' token using an axios call. After that, I then look to set state based upon the response I get from data either provided by the BE or stored in localStorage. Finally, I'm then attempting to console.log the state so that I can make sure the state is updated (which it is).
However, it's just continually re-rendering at the moment and not just loading once.
Note - I'm not displaying any of this information on the page itself, this is simply a processing screen used to complete some BE calls.
Here's my useEffect function:
useEffect(() => {
axios.post("/api/verifyToken", {
token: JSON.parse(localStorage.getItem('auth'))
})
.then((response) => {
setUserId(response.data)
setName(localStorage.getItem('name'))
}).then(() => {
console.log("Testing here..")
console.log(userId)
console.log(name)
})
}, [userId, name])
useEffecthas a dependency onuserIdandname, which you set in the function passed to it, causing it to run the function again, which updatesuserIdand `name, etc.