1
votes

In my react-native app I have an component array with Image component inside, but i have this error

Warning: Failed prop type: Invalid prop source supplied to ForwardRef(Image).

file CampaignPreview

render() {
    return (
        <TouchableOpacity>
            <ImageBackground
                source={ require(this.props.imageFilePath) }
            >
            </ImageBackground>
        </TouchableOpacity>
    );
}

File Home

render() {
    let campaigns = [
        {
            id: 1,
            name: "WildFit",
            expire: 1868029014,
            picFrame: "../assets/picture.jpg",
            done: 0.75
        }
    ];

    let campaignViews = campaigns.map( c => {
        return (
            <CampaignPreview
                imageFilePath={ c.picFrame }
                name={ c.name }
                completation={ c.done }
                key={ c.id }
            />              
        );
    });

    let view = (
        <View>
            <ScrollView>
                { campaignViews }
            </ScrollView>
        </View>
        );

    return view;
}

but If i put string instead of this.props.imageFilePath it works

1

1 Answers

0
votes

i seems that 'require(var)' is not possible in react native, i used require('location') forever, you can try save the string in variable.

require only accept literal s string

react native use variable for image file