import { Effect, ExecutionStrategy, Runtime, Scope } from "effect" import * as React from "react" import type { ScopeOptions } from "./ScopeOptions.js" import { closeScope } from "./internal.js" export const useLayoutEffect: { ( effect: () => Effect.Effect, deps?: React.DependencyList, options?: ScopeOptions, ): Effect.Effect> } = Effect.fn("useLayoutEffect")(function* ( effect: () => Effect.Effect, deps?: React.DependencyList, options?: ScopeOptions, ) { const runtime = yield* Effect.runtime>() React.useLayoutEffect(() => Effect.Do.pipe( Effect.bind("scope", () => Scope.make(options?.finalizerExecutionStrategy ?? ExecutionStrategy.sequential)), Effect.bind("exit", ({ scope }) => Effect.exit(Effect.provideService(effect(), Scope.Scope, scope))), Effect.map(({ scope }) => () => closeScope(scope, runtime, options) ), Runtime.runSync(runtime), ), deps) })