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())), []) +})