Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

Check an Image URL is valid

$
0
0

My goal is to check an image source url to check whether it is valid or not. If it is valid, display the React Native Image as normal and if not, replace it with a local placeholder image. However, the following typescript function never seems to return anything and nothing is displayed.

renderImage(): JSX.Element {    fetch(this.props.imageUrl)    .then(res => {      if(res.status == 404) {        return (<Image            source={require('../images/nasa-logo.png')}            style={styles.imageThumbnail}          />        )      } else {        return (<Image            source={{uri: this.props.imageUrl}}            style={styles.imageThumbnail}          />        )      }    })    .catch(err => {      return (<Image          source={require('../images/nasa-logo.png')}          style={styles.imageThumbnail}        />      )    })    return null // <-- skips to here  }

Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>