Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ludwiigdev/Heroes_App/llms.txt
Use this file to discover all available pages before exploring further.
HeroList is the container component responsible for turning a publisher name into a full, animated grid of hero cards. It accepts a single publisher prop, delegates the data-fetching work to getHeroesByPublisher, and renders one HeroCard per result inside a responsive Bootstrap grid. The filtered list is wrapped in useMemo so that React only re-runs the filter when the publisher value actually changes — not on every parent re-render.
Props
The name of the comic publisher to display. Must be exactly one of the two accepted values below. Any other string causes
getHeroesByPublisher to throw an Error.| Accepted value | Page that uses it |
|---|---|
"Marvel Comics" | MarvelPage (/marvel) |
"DC Comics" | DcPage (/dc) |
Memoization with useMemo
getHeroesByPublisher iterates over the full heroes array on every call. To avoid repeating that work when the parent re-renders for unrelated reasons (e.g. context updates from AuthContext), the result is memoized:
[publisher] means the filtered list is only recomputed when the publisher prop value changes — for example, when the user navigates between the /marvel and /dc routes.
Because the hero dataset is static (imported from
src/Heroes/data/heroes.js at build time), memoization here is primarily a best-practice guard rather than a critical performance optimization. It becomes more impactful if the dataset grows or if filtering logic is made more expensive in the future.Bootstrap grid layout
The wrapping<div> applies three Bootstrap 5 utility classes to create a responsive card grid:
| Class | Effect |
|---|---|
row | Creates a flex-row Bootstrap grid container |
rows-cols-1 | Typo in source — Bootstrap ignores this unknown class; functionally no single-column rule is applied on mobile |
row-cols-md-3 | Three cards per row on medium screens (≥ 768 px) and above |
g-3 | Adds 1rem gutters between cards in both axes |
Delegation to HeroCard
HeroList itself renders no hero UI — it purely maps data to HeroCard instances. Every property from the hero object (id, superhero, alter_ego, first_appearance, characters) is spread onto HeroCard with {...hero}, and the id is also used as the React list key:
Error handling
getHeroesByPublisher validates the publisher name before filtering:
useMemo and will be caught by the nearest React error boundary (or crash the component tree in development).
