Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'width' of undefined when using ImageBackground

I am using the ImageBackground component from React Native. However, no matter what style I choose the same error message always displays. The code looks as it follows:

  render() {
return (
  <ImageBackground
    source={require('./common/Background_image.png')}
    stlye={styles.backgroundStyle}
  >
    <Text>Some text here!!</Text>
  </ImageBackground>
);

}

  backgroundStyle: {
flex: 1,
width: null,
height: null,
resizeMode: 'cover'}

Image of the error here

React-Native version: react-native-cli: 2.0.1 react-native: 0.55.4

Any ideas of what this may happen?

like image 504
marcos-cr Avatar asked Dec 09 '18 18:12

marcos-cr


1 Answers

You are passing stlye but the correct syntax should be style

<ImageBackground
    source={require('./common/Background_image.png')}
    style={styles.backgroundStyle}
>
  <Text>Some text here!!</Text>
</ImageBackground>
like image 136
Helmer Barcos Avatar answered Oct 30 '22 05:10

Helmer Barcos