Working with a react component using hooks. I am attempting to assign values to my state after an Axios call. The data is correctly returned and it appears the state is correctly updated; however, the DOM is not updating with the values. Is this the proper method for doing this?
export const Main = (props) => {
const { token } = useParams()
const [user,setUser] = useState({name:""})
useEffect(()=>{
const getUser = async() =>{
const response = await API.post("usrinfo",{token:token})
setUser({name:response.data.name});
}
getUser()
},[token])
return(
<div className="main-header">{user.name}</div>
);
}
question from:https://stackoverflow.com/questions/65643937/react-hook-initializing-the-state-with-server-call