Holding State in a Common Ancestor Component
To hold state only with component state and props and update it with events, we will store it in the nearest common ancestor component.
State is propagated only through props
and is updated only through events
. In this case, all the state
will live in a shared ancestor of the components that require state. The App component, since it is the root component, is a good default for holding shared state.
To change the state
, a component needs to emit an event
up to the component holding state (the shared ancestor). The shared ancestor needs to update state
according to the event data and type. This in turn causes a re-render, during which the ancestor component passes updated props
to the component reading the state
.
To build a header...