我有一个布局 HOC 调用“withLayout”
interface WithLayoutProps {
isHomePage?: boolean;
}
const withLayout = <P extends object>(Component: ComponentType<P>) => (
props: P & WithLayoutProps,
): ReactElement => {
return (
<div>
{!!isHomePage?<Header1 />:<Header2 />} //How the home page pass the "isHomePage" to there?
<main>
<Component {...props} />
</main>
</div>
);
};
export default withLayout;
所有页面都是这个组件的布局
const Home: NextPage = withLayout(() => {
return (
<div>home</div>
)
})
但是在主页中,我们需要不同的标题,例如<Header1 />
和其他页面使用
我怎么能把道具传递isHomePage
给withlayout
?