From adc8835304bb7333120a24ade95c5e3b57644946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 20 Oct 2025 07:09:49 +0200 Subject: [PATCH] Add useOnMount --- packages/effect-fc/src/Component.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/effect-fc/src/Component.ts b/packages/effect-fc/src/Component.ts index dd1524f..c216237 100644 --- a/packages/effect-fc/src/Component.ts +++ b/packages/effect-fc/src/Component.ts @@ -407,3 +407,15 @@ export const withRuntime: { props, ) }) + +export const useOnMount: { + ( + f: () => Effect.Effect + ): Effect.Effect +} = Effect.fnUntraced(function* ( + f: () => Effect.Effect +) { + const runtime = yield* Effect.runtime() + // biome-ignore lint/correctness/useExhaustiveDependencies: only computed on mount + return yield* React.useMemo(() => Runtime.runSync(runtime)(Effect.cached(f())), []) +})