i am facing problem when i try to return the length of array in react. the error is 'TypeError: Cannot read property 'length' of undefined'. I have put this in another child component and it work but when i tried in NavBar it just show the error.
import React from 'react';
import './NavBar.css';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCartPlus } from '@fortawesome/free-solid-svg-icons';
const NavBar = (props) => {
const order = props.cart
return (
<div className='container-fluid'>
<nav className="navbar navbar-expand-lg navbar-light justify-content-md-between justify-content-center flex-wrap">
<a href="/"><img src="https://i.ibb.co/NZcQbJM/logo2.png" alt="Red Onion Food"/></a>
<div>
<a href="/" className='nav-item' > <FontAwesomeIcon icon={faCartPlus} /></a>
<a href="/" className='nav-item login'>Login</a>
<a href="/" className='nav-item'><button className="btn btn-danger btn-rounded">Sign Up</button></a>
</div>
</nav>
<div><h6>{order.length}</h6></div>
</div>
);
};
export default NavBar;
I dont know what to do!!!
cartthat is an array.cartis, and howcartto be the props of NarBar.