reactjs - 如何正确包装和导出也具有组件作为属性的 React 组件
问题描述
我正在构建一个 React Native 应用程序,并且一直在包装来自各种库的一些组件,以便使用明暗模式正确地对它们进行主题化。
通常我会像这样包装和导出它:
import * as React from 'react';
import { Text as _Text, TextProps as _TextProps } from 'react-native-elements';
import { ThemeProps, useThemeColor } from './Theme';
export type TextProps = ThemeProps & _TextProps & { children: any };
export function Text(props: TextProps) {
const { style, lightColor, darkColor, ...otherProps } = props;
const color = useThemeColor({ light: lightColor, dark: darkColor }, 'text');
return <_Text style={[{ color }, style]} {...otherProps} />;
}
但是,我正在尝试Card
从具有一些子组件的 react-native-elements 包装组件。以下是在任何包装之前如何正常使用组件的示例Card
(取自https://reactnativeelements.com/docs/card/):
<Card>
<Card.Title>CARD WITH DIVIDER</Card.Title>
<Card.Divider/>
{
users.map((u, i) => {
return (
<View key={i} style={styles.user}>
<Image
style={styles.image}
resizeMode="cover"
source={{ uri: u.avatar }}
/>
<Text style={styles.name}>{u.name}</Text>
</View>
);
})
}
</Card>
那么,我如何包装这个Card
组件,并希望它的所有子组件,比如Card.Title
,Card.Divider
它们仍然可以以类似的方式访问?
解决方案
推荐阅读
- android - 将幻灯片过渡应用于 ViewGroup 的子项
- c# - 使用操纵杆在球体上旋转玩家
- django - 将所有时区作为 Django 模型的选择的最佳方式是什么?
- html - 我可以在 ion-content 中创建相机视图吗
- mysql - 无法从本地主机连接到 MySQL 服务器,但 MySQL 服务正在运行
- python - 基于两列合并数据框
- java - 可以更改的java方法
- python - 创建一个文本文件并将其移动到另一个目录[我被卡住了]
- android - 一个或多个布局缺少 layout_width 或 layout_height 属性或自动添加所有缺少的属性
- java - 如何使用 smtp.mail.yahoo.com 发送 Java 电子邮件?