Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
type AllowedChildren =
| React.ReactElement<BasicItemProps>
| React.ReactElement<HeaderItemProps>
| AllowedChildren[];
type ListSectionProps = {
children: AllowedChildren;
};
const childrenTypes = [BasicItem, HeaderItem];
function assertProperType(child: any) {
if (!child?.type || !childrenTypes.includes(child?.type)) {
console.warn(
`Illegal children type for ListSection. Must be one of ${childrenTypes
.map((c) => c.name)
.join(',')}`,
);
}
}
export default function ListSection({children}: ListSectionProps) {
if (__DEV__) {
React.Children.forEach(children, assertProperType);
}
return <View>{children}</View>;
}
type BasicItemProps = PropsWithChildren<{}>;
export function BasicItem({children}: BasicItemProps) {
return (
<View>
<ThemeText>{children}</ThemeText>
</View>
);
}
type HeaderItemProps = {
children?: string;
};
export function HeaderItem({children}: HeaderItemProps) {
return (
<View>
<ThemeText>{children}</ThemeText>
</View>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment