I need to call fectchData
when there's no testData
in context store or input ur
is different from saved testData[0].ur
.
But this constantly request API if there's ur
has empty testData
. Which condition will make trick?
componentDidMount() {
const [state] = this.context;
const { testData } = state;
const fetchData = async () => {
console.log("fetching data");
this.setState({ loading: true });
this.updateTestData();
};
if (testData === "" || testData[0]?.ur !== this.props.ur) fetchData();
}