The initial state of orders
is an empty array:
const [orders, setOrders] = useState([]);
Which has no property called seven
. So when you try to display that state:
<p>{orders.seven.length}</p>
You'll get an error. If the resulting value for orders
isn't an array then you shouldn't set it to one to begin with. Give it the structure you expect:
const [orders, setOrders] = useState({ seven: [] });
This would initialize it to an object with a property called seven
which itself is an empty array. Then the length
will correctly be 0
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…