Think about what's going on here.
The page and all its assets are loaded in the browser, scripts are launched, and all React components are displayed. Only after they are displayed do you receive your data. So, of course, there will be an initial state, followed by a loaded state.
So, how do you feel about the state of your application before the data gets in?
You have already expressed your unacceptable hostility to presenting an application with empty data. You can defer rendering of your application until data arrives. But this will lead to a terrible user experience. They can look at a blank page for a few seconds before something happens.
Or there’s an old bootloader trick. You might have something like isLoading: true in your initial state. This corresponds to some visual loading indicator (a traditionally rotating GIF image) in the React component. This is by far the best option if you must upload your data via AJAX.
The best way
But here's the thing: you don't need to use AJAX for your initial state. You can completely avoid this delay by adding your details to the page.
<script> </script>
Now you only need to “moisturize” your store when you create it.
const store = createStore(rootReducer, window.__INITIAL_DATA__);
David L. Walsh
source share