I have an api that fetches names(usernames) based on country somewhere along the lines of.
/names/{countryName}
and the UI has two tabs - being Australia
and India
. For this I'm using material ui tabs in react.
Once the user clicks India it calls /names/India
and fetches a list of names (close to 200). Similarly it goes for Australia.
When the call is made to the backend I'm showing a loader in the frontend. Then I'm storing the result in an object called names
in state. names['India']
and names['Australia']
is an array of 200 values each. These names are shown in a table with the names and a random image generated from the names. And this is all working fine.
Problem starts when a user switches back and forth the tabs. Since the data is already there in the state, so no new call is made. But even then the rendering is slow. It remains on the old tab until data in new tab is rendered and only then it switches to the new tab and this is misleading to the end user.
I was thinking of using react-window-infinite-loader
but that is more useful when you are fetching data page by page and the api returns you data that way. But right now, the data is anyway there on state. Why is it taking so much time to render it, how can I avoid this?