One Source of Truth
Your app now has several pieces of state, and each of them lives in exactly one place: favorites and search in App. Every component that shows them gets them as props, and every change goes through a function that App passed down. That's what one source of truth means: each piece of data is stored once, and everything else is read or computed from it. When the user stars a band, the star, the header and the lineup change together, because they all come from the same favorites.
When you add a feature, ask three questions:
- What does the user change? That's state.
- Which components need it? The state goes into their closest common parent and comes down to them as props, with a function that changes it.
- What can be worked out from what you already have? Compute it while rendering, don't store it.
A list can go through several filters, one after another. With let, the list starts as the result of one filter, and an if filters it again:
let shownBands = bands.filter((band) => band.stage === stage);
if (fridayOnly) {
shownBands = shownBands.filter((band) => band.day === "Friday");
}Sometimes, data has to go many levels down, through components that don't use it themselves and only pass it on. For that, React has context, which a component deep down can read without its parents passing it along. In apps the size of yours, props are simpler and clearer.
Instructions
In Filters, add a checkbox Only favorites with the id only-favorites. Keep whether it's ticked in App, in a state variable onlyFavorites that starts as false, and pass Filters the props onlyFavorites and onOnlyFavoritesChange.
While Only favorites is ticked, the lineup shows only the favorite bands, and the search still works among them.