Creating a component to wrap every page with the hope of receiving children and title for each page is throwing error. "Title element received an array with more than 1 element as children."
import Head from "next/head";
interface IProps {
children: JSX.Element;
title?: string;
restProps?: any;
}
export default function MetaDataContainer(props: IProps) {
const {
children,
title = "Generated by create next app",
...restProps
} = props;
return (
<>
<Head>
<title>CV-stack - {title}</title>
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>{children}</main>
</>
);
}
2
Answers
I saw a solution online on this link.
Below is the sample code that works:
Notice that the title is now a single node with {
CV-stack - ${title}
} instead of CV-stack - {title}You need to provide an object like so
Because of the reasons explained in this comment (react dom string rendering) https://github.com/vercel/next.js/discussions/38256