blob: 9ff57e32295d8ca8feb22586ffd3063b0d35fc77 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import type { WritableAtom } from "jotai";
import { useHydrateAtoms } from "jotai/utils";
import type { ReactNode } from "react";
type AnyWritableAtom = WritableAtom<unknown, unknown[], unknown>;
/**
* Component that hydrates Jotai atoms with initial values before rendering children.
* Use this in tests to pre-populate async atoms, bypassing Suspense.
*/
export function HydrateAtoms({
initialValues,
children,
}: {
initialValues: Iterable<readonly [AnyWritableAtom, unknown]>;
children: ReactNode;
}) {
useHydrateAtoms([...initialValues]);
return <>{children}</>;
}
|