Skip to content

Commit db4794f

Browse files
committed
Add locale to prefetching
1 parent 2b4cce8 commit db4794f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/react/src/prefetch.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,30 @@ import {
88
fetchStationExtremes,
99
fetchStations,
1010
} from "./client.js";
11-
import { getDefaultRange } from "./utils/defaults.js";
11+
import { getDefaultRange, getDefaultUnits } from "./utils/defaults.js";
1212

1313
export interface PrefetchTideStationOptions {
14-
units: Units;
14+
units?: Units;
15+
locale?: string;
1516
datum?: string;
1617
}
1718

1819
/**
1920
* Prefetch all queries that the `<TideStation>` component will make.
2021
* Call this on the server, then use `dehydrate(queryClient)` to pass the
21-
* cache to the client via `<HydrationBoundary>`.
22+
* cache to the client via a pre-hydrated QueryClient.
23+
*
24+
* Pass either `units` directly or `locale` to derive units automatically.
2225
*/
2326
export async function prefetchTideStation(
2427
queryClient: QueryClient,
2528
baseUrl: string,
2629
id: string,
27-
{ units, datum }: PrefetchTideStationOptions,
30+
{ units, locale, datum }: PrefetchTideStationOptions = {},
2831
): Promise<void> {
32+
const resolvedUnits = units ?? getDefaultUnits(locale);
2933
const range = getDefaultRange();
30-
const params = { id, start: range.start, end: range.end, units, datum };
34+
const params = { id, start: range.start, end: range.end, units: resolvedUnits, datum };
3135

3236
await Promise.all([
3337
queryClient.prefetchQuery({

0 commit comments

Comments
 (0)