Isaac Sekamatte
Isaac Sekamatte

Reputation: 5598

Data cached on reloading react-native app

I am very new to react-native and js. I have been having this issue for some time now. I created a react native app that picks data from a server in form of a JSON. This data is then used when rendering my views. I am currently using a static JSON file on the server having the data I want to use inside the app. My challenge is that when I edit my JSON file on the server, this is not reflected on the app.

This is how I change state inside my app.

 componentDidMount()
 {
    axios.get('link_to_my_server/names.json')
         .then(response => this.setState({ albums: response.data }));
 }

I have removed the link to the server to avoid disturbances but I guess what I have said makes sense.

Now my question is: How do I get my data to change inside app when I reload app after changing data inside names.json on the server?

Upvotes: 2

Views: 218

Answers (1)

Isaac Sekamatte
Isaac Sekamatte

Reputation: 5598

This was my mistake, I was passing a json file with similar names for images on server. I would change the image but give a similar name as before. The images would never be reloaded from server on phone, they were simply catched given that they had a similar name. The solution was to upload images with entirely different names and send the new json the app, that way the images changed as expected.

Upvotes: 1

Related Questions