This is how I am trying to populate two dropdowns in my component using useEffects.
function populate_dropdown_one_data() {
return axios.get("http://127.0.0.1:5001/dropdownonedata");
}
function populate_dropdown_two_data() {
return axios.get("http://127.0.0.1:5000/dropdowntwodata");
}
React.useEffect(() => {
populate_dropdown_one_data()
.then(result => {
setDropDownOneData(result.data.data);
});
}, []);
React.useEffect(() => {
populate_dropdown_two_data()
.then(result => {
setDropDownTwoData(result.data.data);
});
}, []);
This only calls populate_dropdown_one_data when the page loads.
If I combine populate_dropdown_one_data and populate_dropdown_two_data inside one useEffect, it only calls populate_dropdown_two_data.
How do I populate data for both the dropdowns when the page loads?
promise.allReact.useEffect(() => Promise.all([populate_dropdown_one_data, populate_dropdown_one_data]).then(values => setDropDownData(values)) , [])alertin theuseEffects. You are right. Both are called but only one makes the call to the server (populate_dropdown_two_data). I think I may have to useasync awaitinuseEffectshere?