In my project, when I am unable to change document.title (the title of the document) after fetching data through API. My code is as follows:
useEffect(() => {
loadData();
console.log(name)
document.title = `${name}`
}, []);
const loadData= async () => {
axios.get('https://api.themoviedb.org/3/movie/' + props.match.params.id + '?api_key=***').then(
res=>{
setName(res.data.title)}
)}
However, the console.log does correctly show the name. How to fix this?