[英]Pass props to child component - React Native
I want to pass props color
to a icon child. 我想将道具
color
传递给图标孩子。 This <Feather />
I want to add color
as props 这个
<Feather />
我想添加color
作为道具
This is my component and the Feather child 这是我的组成部分和羽毛的孩子
import { Feather } from '@expo/vector-icons'
export default class CloseButton extends React.PureComponent {
render () {
const { style, ...props } = this.props
return (
<TouchableOpacity style={styles.close} link {...props} >
<Feather name='x' size={26} /> // <-- want add color here
</TouchableOpacity>
)
}
}
This is my component where I send props thas show in ThouchableOpacity
这是我在
ThouchableOpacity
发送道具的组件
<Alert.CloseButton onPress={props.onRequestClose} />
How can pass color in this props and it only show on icon? 如何在这个道具中传递颜色,它只显示在图标上?
You could use a prop called color
for your CloseButton
component that you pass to the Feather
component. 您可以将一个名为
color
的prop用于您传递给Feather
组件的CloseButton
组件。
export default class CloseButton extends React.PureComponent {
render () {
const { style, color, ...props } = this.props;
return (
<TouchableOpacity style={styles.close} link {...props} >
<Feather name='x' size={26} color={color} />
</TouchableOpacity>
)
}
}
Usage 用法
<Alert.CloseButton
onPress={props.onRequestClose}
color="red"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.