Skip to content

[Dashboard] Create reusable hooks for pulling data from backend #15

Description

@henrybednarz

Goal: We want to build a clean data-fetching layer in the React frontend that the rest of the dashboard can rely on. Rather than making raw fetch calls scattered throughout components, we want a set of reusable React hooks that encapsulate fetching, loading state, and error handling for each endpoint. This gives every dashboard view a consistent, predictable way to pull data.

Technical Description:

  • Create a custom hook for each backend endpoint defined in the API contract (e.g. useRaceData, useLapData, usePositionsByBounds, etc.)
  • Each hook should expose data, isLoading, and error states
  • Create a shared API client (e.g. src/api/client.ts) that centralizes the base URL and any shared headers, so individual hooks don't hardcode fetch logic
  • Hooks should accept the relevant input parameters matching the API spec (e.g. raceId, lapNumber, boundingBox) and pass them through to the correct endpoint

Conditions of Satisfaction:

  • A reusable hook exists for every endpoint in the API contract
  • Each hook correctly manages loading, success, and error states
  • Hooks can be dropped into any component without additional fetch logic

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions