React statebeginner
State is the data that changes while the page is open; useState is how a component remembers something between renders.
useState([]) infers never[], so nothing can ever be added to the queue, and useState(null) can only ever hold null. The total is stored separately and drifts. Type the state, and derive the total.
The queue is Order[], the selection is Order | null, the total is derived, and the screen shows the real queue.
Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.
State is the data that changes while the page is open; useState is how a component remembers something between renders.
A type is a note to your future self that the compiler checks — annotating what goes in and what comes out is where most of the value is, before any advanced feature.