''undefined is not an object' when using ImageBackground React Native
I receive the error 'undefined is not an object (evaluating 'asset.scales' when trying to set the background image, anyone knows why even if everything seems fine.
import { ImageBackground, StyleSheet } from 'react-native-web'
function WelcomePage() {
return (<ImageBackground source={require('../assets/background.jpg')} style={{width: '100%', height: '100%'}} resizeMode="cover" >
</ImageBackground>)
}
const styles = StyleSheet.create({
backGround: {
flex: 1,
width: '100%',
height: '100%',
}
})
export default WelcomePage
Solution 1:[1]
You are using the wrong import for ImageBackground. Change your import to the following.
import { ImageBackground } from 'react-native';
Compare this with the documentation of react-native-web.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Scholz |
