Compare commits
1 Commits
27bbedda82
...
129eee7ac5
| Author | SHA1 | Date | |
|---|---|---|---|
| 129eee7ac5 |
@@ -578,17 +578,21 @@ export const useReactLayoutEffect: {
|
|||||||
React.useLayoutEffect(() => runReactEffect(runtime, f, options), deps)
|
React.useLayoutEffect(() => runReactEffect(runtime, f, options), deps)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const useRunSync = <R = never>(): Effect.Effect<
|
export const useRunSync: {
|
||||||
<A, E = never>(effect: Effect.Effect<A, E, Scope.Scope | R>) => A,
|
<R = never>(): Effect.Effect<<A, E = never>(effect: Effect.Effect<A, E, R>) => A, never, Scope.Scope | R>
|
||||||
never,
|
} = Effect.fnUntraced(function* <Args extends unknown[], A, E, R>(
|
||||||
Scope.Scope | R
|
f: (...args: Args) => Effect.Effect<A, E, R>,
|
||||||
> => Effect.andThen(Effect.runtime(), Runtime.runSync)
|
deps: React.DependencyList,
|
||||||
|
) {
|
||||||
|
// biome-ignore lint/style/noNonNullAssertion: context initialization
|
||||||
|
const runtimeRef = React.useRef<Runtime.Runtime<R>>(null!)
|
||||||
|
runtimeRef.current = yield* Effect.runtime<R>()
|
||||||
|
|
||||||
export const useRunPromise = <R = never>(): Effect.Effect<
|
Runtime.runSync()
|
||||||
<A, E = never>(effect: Effect.Effect<A, E, Scope.Scope | R>) => Promise<A>,
|
|
||||||
never,
|
// biome-ignore lint/correctness/useExhaustiveDependencies: use of React.DependencyList
|
||||||
Scope.Scope | R
|
return React.useCallback((...args: Args) => Runtime.runSync(runtimeRef.current)(f(...args)), deps)
|
||||||
> => Effect.andThen(Effect.runtime(), context => Runtime.runPromise(context))
|
})
|
||||||
|
|
||||||
export const useCallbackSync: {
|
export const useCallbackSync: {
|
||||||
<Args extends unknown[], A, E, R>(
|
<Args extends unknown[], A, E, R>(
|
||||||
|
|||||||
Reference in New Issue
Block a user