Reactjs 在React Native中将道具传递给子元素的正确方法是什么?
我将react-native与react-native纸张一起使用,并创建了以下GenericButton:Reactjs 在React Native中将道具传递给子元素的正确方法是什么?,reactjs,react-native,Reactjs,React Native,我将react-native与react-native纸张一起使用,并创建了以下GenericButton: const GenericButton = props => { return ( <TouchableRipple onPress={props.onPress} style={{ ...styles.container, backgroundColor: props.backgroun
const GenericButton = props => {
return (
<TouchableRipple
onPress={props.onPress}
style={{
...styles.container,
backgroundColor: props.backgroundColor,
borderWidth: props.borderWidth,
borderColor: props.borderColor,
width: props.width,
height: props.height
}}
rippleColor={props.rippleColor}
disabled={props.disabled}
borderless
>
{props.children}
</TouchableRipple>
); };
const GenericButton=props=>{
返回(
{props.children}
); };
然后,我有一个custoButton,它是一个具有自定义逻辑的通用按钮:
const ImgButton = props => {
return (
<GenericButton
onPress={props.onPress}
backgroundColor={props.backgroundColor}
borderWidth={props.borderWidth}
borderColor={props.borderColor}
width={props.width}
height={props.height}
rippleColor={props.rippleColor}
disabled={props.disabled}
>
<View style={styles.button}>
<Image source={props.source} style={styles.icon} />
<Text
style={{
...styles.text,
color: props.textColor,
fontSize: props.textFontSize
}}
>
{props.text}
</Text>
</View>
</GenericButton>
); };
const ImgButton=props=>{
返回(
{props.text}
); };
如您所见,我正在重用ImgButton中GenericButton的所有道具,以便将信息传递给相关组件
有更好的方法吗?我只想在ImgButton和GenericButton组件之间建立一个“桥梁”。我在ImgButton组件的GenericButton标记中尝试了{…props}
,但是ImgButton的所有props都被传递给GenericButton。有没有办法只传递GenericButton需要的道具而不传递其他道具