I am converting React Lifecycles to Hooks. App.js page is loading the first page's data before axios & store configs are run. Because of this, the wrong axios.baseURL is being used in the apis.
I replaced componentWillMount with useEffect, but it runs after the useEffect used on the first loaded page.
APP.JS
const App = () => {
useEffect(() => {
(async () => await AxiosConfig.init())();
}, []);
useEffect(() => {
(async () => await Store.init())();
}, []);
return (
<Provider store={store}>
<Router>
<Switch>
...
</Switch>
</Router>
</Provider>
);
}
LOADING PAGE
const [data, setData] = useState(null);
const getData = useCallback(filters => {
(async () => {
try {
let response = await DataService.getAllData(filters);
if (response && response.status === 200) {
let data = response.data && response.data.result;
setData(data);
}
} catch (error) {
...
}
})();
}, []);
useEffect(() => getData(filters), [filters, getData]);
<List data={data} />
How do i fix the timing so the config runs first? Do I need to combine the calls in one useEffect, set a flag upon success responses, and only return the App.js DOM if flag = true?