aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/test/atomTestUtils.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/test/atomTestUtils.tsx')
-rw-r--r--src/client/test/atomTestUtils.tsx20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/client/test/atomTestUtils.tsx b/src/client/test/atomTestUtils.tsx
new file mode 100644
index 0000000..9ff57e3
--- /dev/null
+++ b/src/client/test/atomTestUtils.tsx
@@ -0,0 +1,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}</>;
+}