我有两个 HoC 组件。首先必须充当一些布局包装器,其中将包含一些用于移动渲染等的逻辑。
const LayoutWrapper = (Component: React.FC<any>): React.FC<any> => {
const Layout = () => {
const [layout, set] = React.useState("layout state");
return <Component
layout={layout}
/>;
}
return Layout;
} export default LayoutWrapper;
如果用户登录,第二个 HoC 将处理。
const Secured = (Component: React.FC<any>): React.FC<any> => {
const Wrapped = () => {
const [securedPagestate, set] = React.useState("secured page state");
const Layout = LayoutWrapper(Component);
return <Layout test={securedPagestate} />
}
return Wrapped;
}
export default Secured;
我已经包装了将呈现实际页面的主页组件,它需要从上面显示的两个 HoC 组件传递道具,但我只从 LayoutWrapper Hoc 而不是 Secured Hoc 组件获取道具。它实际上有什么问题?
const HomepageView = (props: HomepageViewProps) => {
return <>HOMEPAGE</>;
}
export default Secured(HomepageView);