'React.js giving TypeError : Cannot read properties of undefined (reading 'length')

<MDBRow className="mt-5">
        {tours.length === 0 &&  (
          <MDBTypography className="text-center mb-0" tag="h2">
            No Tours Found
          </MDBTypography>
        )}
        <MDBCol>
          <MDBContainer>
            <MDBRow className="row-cols-1 row-cols-md-3 g-2">
              {tours && tours.map((item, index) => <CardTour key={index} {...item} />)}
            </MDBRow>

I have tried to wrap the {tours.length} the error is still there. I am learning from home I know it might not that big issue but searched for solution. the whole is only affected by this tours.length issue. please help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source