Without using jQuery or any other library (only vanilla js) I want the best way to execute a second method (of a class) after the first one has completed.
This is with respect to a react native expo app I'm creating. I want my second method to execute immediately after the first one
method 1
async load() {
try {
let mydata = await AsyncStorage.getItem("MyWeeklyTasks");
if (mydata !== null) {
this.state.products = JSON.parse(mydata);
data2 = JSON.parse(mydata);
} else {
this.state.products = [];
}
} catch (err) {
alert(err);
}
}
method 2
setDataForDay(whichDay) {
this.load();
this.state.whichDay = whichDay;
let filtered;
if (whichDay == "all") {
filtered = this.state.products;
// filtered = data2;
} else {
filtered = this.state.products.filter((obj) => {
return obj.day === whichDay;
});
}
this.state.products = filtered;
this.forceUpdateHandler();
}
This is my constructor
constructor(props) {
super(props);
this.load();
this.state = {
useThisId: "",
inputTitle: "",
inputDesc: "",
products: data2,
modalsetVisible: false,
dataModalSetVisible: false,
whichDay: "all",
color: "white",
};
this.contentForModal = {
content: "",
};
this.setDataForDay(this.state.whichDay);
this.forceUpdateHandler = this.forceUpdateHandler.bind(this);
alert("Click on the Day you wish to see");
}
In addition to the constructor I'm also calling load whenever the data is getting updated.