skip to Main Content

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


  1. You should try these types of conditions

    {data ? <MainPage/> : null}
    
    {data ? <MainPage/> : <Home/>}
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search