Heroes App ships three pure helper functions that cover every way the UI queries hero data: exact lookup by ID, case-insensitive name search, and publisher-based filtering. All three operate on the same static in-memory array exported fromDocumentation 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.
src/Heroes/data/heroes.js, so they are fully synchronous and require no network calls or async handling.
Heroes Data Module
The heroes dataset lives atsrc/Heroes/data/heroes.js and exports a single constant array named heroes. It contains 20 entries — 10 DC Comics heroes (IDs prefixed dc-) and 10 Marvel Comics heroes (IDs prefixed marvel-). The array is a plain JavaScript export; there are no API calls, no lazy loading, and no external dependencies.
Each object in the array has the following shape:
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier, e.g. "dc-batman" |
superhero | string | Hero’s superhero name, e.g. "Batman" |
publisher | string | Either "DC Comics" or "Marvel Comics" |
alter_ego | string | Civilian identity, e.g. "Bruce Wayne" |
first_appearance | string | Issue and year of first appearance |
characters | string | Real-world characters portrayed by this hero |
Importing the Helpers
All three helpers are re-exported from a single barrel file atsrc/Heroes/helpers/index.js, so you can import any combination in one statement:
The
index.js barrel re-exports getHeroById, getHeroesByName, and getHeroesByPublisher. You never need to import from the individual files directly.getHeroById
getHeroById performs an exact match on the id field of every hero in the dataset and returns the first (and only) match. It is used in HeroPage wrapped in a useMemo to avoid re-computing on every render.
Signature
Parameters
The unique hero identifier to look up. IDs follow the pattern
"<publisher-prefix>-<heroname>", for example "dc-batman" or "marvel-spider". The match is case-sensitive and must be exact.Return Value
The Hero object whose
id exactly matches the argument, or undefined if no hero is found. Because IDs are unique in the dataset, this function will never return more than one result.Edge Cases
- Returns
undefinedfor any ID not present in the dataset — always guard the return value before accessing its properties. - The match is exact and case-sensitive:
"DC-Batman"will not match"dc-batman".
Example
getHeroesByName
getHeroesByName performs a case-insensitive, partial-string match against each hero’s superhero field. It is used in SearchPage to filter the hero list as the user types.
Signature
Parameters
The search string to match against hero names. Leading and trailing whitespace is trimmed automatically. The comparison is case-insensitive (uses
toLocaleLowerCase() on both sides), so "bat", "BAT", and " Bat " all match "Batman".Return Value
An array of Hero objects whose
superhero name contains name as a substring. Returns an empty array [] when the trimmed input is an empty string — it never returns the full dataset for a blank query.Edge Cases
- An empty string (
"") or a whitespace-only string (" ") returns[], preventing the UI from unintentionally rendering the full hero list. - Matching is on the
superherofield only — searching byalter_egoorcharactersis not supported. - Returns multiple results when the query matches more than one hero (e.g.,
"man"matches Batman, Superman, Spider-Man, etc.).
Example
getHeroesByPublisher
getHeroesByPublisher returns all heroes belonging to a given publisher. It validates the publisher argument against an allowlist before filtering, throwing a descriptive error for any unrecognised value. It is used in HeroList wrapped in useMemo.
Signature
Parameters
The publisher to filter by. Must be one of the two accepted values:
"DC Comics"— returns the 10 DC heroes"Marvel Comics"— returns the 10 Marvel heroes
===), so it is case-sensitive. Passing "dc comics" or "Marvel" will throw an error.Return Value
An array of Hero objects whose
publisher field exactly matches the argument. Returns 10 heroes for each valid publisher. The array is a subset of the original heroes array — objects are not copied.Errors
Throws a standard
Error with the message "<publisher> is not a valid publisher" when the publisher argument is not in the ["DC Comics", "Marvel Comics"] allowlist. This makes misconfigured route parameters or typos fail loudly during development.Example
Always pass one of the two exact strings —
"DC Comics" or "Marvel Comics" — to avoid the thrown Error. These strings match the publisher values stored in heroes.js character-for-character, including capitalisation and the word “Comics”.Quick Reference
getHeroById
Exact ID lookup. Returns a single Hero object or
undefined. Used in HeroPage via useMemo.getHeroesByName
Case-insensitive partial name search. Returns an array (empty for blank input). Used in
SearchPage.getHeroesByPublisher
Publisher filter with allowlist validation. Throws for invalid publishers. Used in
HeroList.