0

So I have a fetch() call returning a background url labeled as data in the following code. The url is a user uploaded image and makes a call to my backend for uploaded image.

await fetch(URL3)
  .then(response => response.json())
  .then(data => {
    this.setState({
      userBackground: data,
      loading: false
    });
  });

After I made this call with a jpeg file (37 kb) it will not show any other file except the first jpeg I uploaded. I have tried png and jpeg files of varying sizes.

Is there some type of image cache on android that is being activated and not allowing another image to be downloaded????

My ImageBackground tag is as follows:

<ImageBackground
    source={this.state.userBackground === null ? this.state.background : { uri: `${uri}` }}
    style={{ width: '100%', height: '100%' }}
  >

1 Answer 1

3

React native internally does the image caching, to get rid of this you can append the image url with time stamp. For instance,

let imageUrl = `${this.state.userBackground}?time=`+new Date(); 
<ImageBackground
source={imageUrl}
style={{ width: '100%', height: '100%' }}
>
Sign up to request clarification or add additional context in comments.

1 Comment

This causes infinite rerenders as each render passes different props

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.