I have a realtime application that fetches a set of data that remains static and another set every second.
The problem is that event if I test the application with an imported json instead of fetching it and set the app state with that json, I have errors because the state on mount is empty… I tried to insert some conditional like
{data && <MainPage/>}
but still have errors on MainPage children like "Cannot read properties of undefined (reading ‘0’)" because I’m passing parts of the json to the children as props.
How can I solve this?
2
Answers
You should try these types of conditions
If the data is array you can check
data.length != 0
or if it’s object you can check if it’s empty or not