Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在React Native中将道具传递给子元素的正确方法是什么?_Reactjs_React Native - Fatal编程技术网

Reactjs 在React Native中将道具传递给子元素的正确方法是什么?

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

我将react-native与react-native纸张一起使用,并创建了以下GenericButton:

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需要的道具而不传递其他道具