The variable userInfo
is correctly shown in the console, but can't be set for the state.
It works the second time so I assume the state is being set before data is correctly retrieved.
const [userData, setUserData] = useState({});
try {
const response = await axios.post("/usuarios/oauth-twitch", { data: code });
const userInfo = await response.data.user_data;
console.log(userInfo);
setUserData(userInfo);
} catch (error) {
console.log(error);
}