I am getting dynamic title and log from API and passing it to nextJS Head for og:title and og:image. but it is not working. Any idea how can I make it work.
Here is my code.
function PageHead(props: any) {
let location = "/";
if (process.browser) {
location = window.location.href;
}
console.log(props);
return (
<Head>
<meta property="og:title" content={props.title} />
<meta property="og:url" content={location} />
<meta property="og:image" content={props.logo} />
</Head>
);
}
const Home: NextPage = () => {
const [title, setTitle] = useState('');
const [logo, setLogo] = useState('');
useEffect(() => {
(async () => {
const reviewData = await (await fetch("https://api.")).json();
setTitle(reviewData.name);
setLogo(reviewData.logo);
})();
}, []);
return (
<React.Fragment>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
minHeight: '100vh',
}}
>
<PageHead logo={logo} title={title}/>
</Box>
</React.Fragment>
)
}
export default Home
After I export static site or run as a dev. when I refresh the page, in console.log I get the following 3 logs one after another. This tells me that it does get the logo and title from api one by one and refresh console but for some reason does not populate it within HEAD for title and image tag.
Any idea how can I fix it.