react-native 子组件声明
作者:
朱传武 | 来源:发表于
2021-12-13 10:22 被阅读0次import React, { PropsWithChildren } from 'react';
export interface LayoutProps {}
export interface LayoutHeaderProps {} // 采用ParentChildProps形式命名
export interface LayoutFooterProps {}
export function Layout(props: PropsWithChildren<LayoutProps>) {
return <div className="layout">{props.children}</div>;
}
// 作为父组件的属性
Layout.Header = (props: PropsWithChildren<LayoutHeaderProps>) => {
return <div className="header">{props.children}</div>;
};
Layout.Footer = (props: PropsWithChildren<LayoutFooterProps>) => {
return <div className="footer">{props.children}</div>;
};
// Test
<Layout>
<Layout.Header>header</Layout.Header>
<Layout.Footer>footer</Layout.Footer>
</Layout>;
本文标题:react-native 子组件声明
本文链接:https://www.haomeiwen.com/subject/jmkgtrtx.html
网友评论