首页 > 解决方案 > React Native ERROR Invalid call require(imagePath)

问题描述

实际上我有一个问题,我正在尝试将路径图像发送到组件道具中,但程序无法正常工作。错误是“第 10 行的无效调用:require(imagePath)”

向组件发送道具:

<ImageTopRegister titleText ="Bienvenido a Sparkit" descriptionText ="Ingresa tus datos personales" imagePath= "../../../assets/images/RegisterName.png" />

零件:

const ImageTopRegister = props =>{    

return (
    
    <ImageBackground style={styles.imageBackground} source={ require(props.imagePath)}>
        <View style={styles.sparkitContainer}>
            <Text style={styles.sparkitText}>Sparkit</Text>                            
        </View>
        <View style={styles.textContainer}>                            
            <Image style={styles.imageSparkit} source={ require('../../../assets/images/sparkiticon.png')}/>
            <Text style={styles.titleText}>{props.titleText}</Text>
            <Text style={styles.descriptionText}>{props.descriptionText}</Text>
        </View>                   
    </ImageBackground>        
  );

};

标签: node.jsreactjsreact-nativecomponentsreact-props

解决方案


推荐阅读