Page load sequence
User requests a route
The browser sends an HTTP request to Vercel. The
@astrojs/vercel SSR adapter invokes the Astro server function for the matching route.Astro renders the HTML shell
Astro evaluates the
.astro page file on the server, generates the HTML layout and static markup, and sends it to the browser. React component markup is included as empty placeholders at this stage.Browser receives HTML and loads scripts
The browser parses the HTML and downloads the JavaScript bundles for any component marked
client:load.React islands hydrate
React mounts each component into its placeholder DOM node. Each component initialises its own state — typically
data: null, loading: true, error: null.useEffect triggers API fetch
On mount, each component’s
useEffect hook fires and calls fetch() against the relevant external API endpoint.Response parsed and stored in state
When the API responds, the component calls
setData() with the parsed JSON, sets loading: false, and React re-renders with the live data.Independent component fetching
Each React island fetches its own data independently. There is no shared data layer or global store. A typical component looks like this:[] ensures the fetch runs once on mount.
Error handling
Every component wraps its fetch logic in atry/catch block:
- Network errors (no connection, DNS failure) are caught and stored in
errorstate. - HTTP errors (4xx, 5xx) are detected by checking
res.okand throwing explicitly. - Parsing errors (malformed JSON) are also caught by the same
catchblock.
error is non-null, the component renders an error message instead of the data UI. This prevents blank or broken layouts when an API is unavailable.
Error boundaries are not used at the React tree level. Each component handles its own errors locally, so one failing component does not affect others on the same page.
Loading states
Whileloading is true, components render a placeholder UI rather than an empty container. Depending on the component:
- Skeleton loaders — placeholder blocks that match the shape of the final content (tables, cards).
- Spinners — animated indicators for charts that take longer to render.
Inflation calculator formula
TheInflationCalculator component fetches the monthly CPI series from ArgentinaDatos and computes the real purchasing-power change between two user-selected dates.
The API returns each month’s CPI as a percentage change (e.g., 20.6 means prices rose 20.6% that month). To get the cumulative change across a range, the component multiplies together the monthly inflation factors for every month in the selected range:
r is the valor field for that month in the API response.
The annualized and average monthly rates are then derived:
- Fetches the full monthly series once on mount and sorts it by date.
- Slices the array to the months between the user’s selected start and end dates.
- Applies the compound multiplication above using
Array.reduce. - Recalculates reactively whenever the user changes the amount or date fields (via
useCallback).
Each
valor in the API response is a month-over-month percentage change, not a cumulative index level. The compound product formula is required to get the correct total inflation across multiple months.API endpoints used
| Component | API | Endpoint |
|---|---|---|
InflationCalculator | ArgentinaDatos | /v1/finanzas/indices/inflacion |
InflationGraph / InflationChart | ArgentinaDatos | /v1/finanzas/indices/inflacion |
DollarPrices | DolarAPI | /v1/dolares |
DollarHistoryChart | ArgentinaDatos | /v1/cotizaciones/dolares/{casa} |