Sharing State - Row & Seat Components
Explore managing shared state in React by using the Row component to control seat statuses and interactions. Understand how to pass event handlers to child Seat components and implement click-based state changes that trigger re-renders. Gain insight into separating data logic from UI concerns and optimizing state updates for interactive seat selections.
We'll cover the following...
Row Component
The rows in the venue body are the same as before, except we are passing the number of tickets to buy as a new prop in the object.
The Row component has gotten a lot more functionality, some of which has been taken from the Seat component. In this version of the code, the status of a seat depends on the status of the seats next to it—if two tickets are bought, then a set with an already sold seat to its right is not available. Because an individual seat can no longer contain all the data needed to ascertain its status, the status for the entire row needs to be stored in the Row component.
Here’s the Row code:
This component keeps track of the seat statuses in an array ...