Answer the question
In order to leave comments, you need to log in
How to make automatic page refresh?
I have a question.
My function takes data from firebase. This date is updated periodically.
Data parses elements onto the screen (data.map).
How can I make it so that every time I visit the page, the data is updated?
Now the function is called via componentDidMount.
Answer the question
In order to leave comments, you need to log in
Try componentWillMount()
import React, { Component } from 'react';
import { View, Text } from 'react-native';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data : null
};
}
componentWillMount() {
this.renderMyData();
}
renderMyData(){
fetch('https://your url')
.then((response) => response.json())
.then((responseJson) => {
this.setState({ data : responseJson })
})
.catch((error) => {
console.error(error);
});
}
render(){
return(
<View>
{this.state.data ? <MyComponent data={this.state.data} /> : <MyLoadingComponnents /> }
</View>
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question