@@ -226,44 +226,18 @@ export class Reffuse<R> {
|
||||
])
|
||||
}
|
||||
|
||||
// useSuspense<A, E>(
|
||||
// effect: Effect.Effect<A, E, R>,
|
||||
// deps?: React.DependencyList,
|
||||
// options?: { readonly signal?: AbortSignal } & RenderOptions,
|
||||
// ): A {
|
||||
// const runPromise = this.useRunPromise()
|
||||
|
||||
// const promise = React.useMemo(() => runPromise(effect, options), [
|
||||
// ...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runPromise],
|
||||
// ...(deps ?? []),
|
||||
// ])
|
||||
// return React.use(promise)
|
||||
// }
|
||||
|
||||
useSuspense<A, E>(
|
||||
effect: Effect.Effect<A, E, R>,
|
||||
deps?: React.DependencyList,
|
||||
options?: RenderOptions,
|
||||
options?: { readonly signal?: AbortSignal } & RenderOptions,
|
||||
): A {
|
||||
const runSync = this.useRunPromise()
|
||||
const runCallback = this.useRunCallback()
|
||||
const runPromise = this.useRunPromise()
|
||||
|
||||
const promiseRef = React.useRef(Promise.withResolvers<A>().promise)
|
||||
|
||||
React.useEffect(() => {
|
||||
const { promise, resolve, reject } = Promise.withResolvers<A>()
|
||||
promiseRef.current = promise
|
||||
|
||||
runCallback(effect, {
|
||||
onExit: Exit.mapBoth({
|
||||
onSuccess: resolve,
|
||||
onFailure: reject,
|
||||
})
|
||||
})
|
||||
}, deps)
|
||||
|
||||
console.log(promiseRef.current)
|
||||
return React.use(promiseRef.current)
|
||||
const promise = React.useMemo(() => runPromise(effect, options), [
|
||||
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runPromise],
|
||||
...(deps ?? []),
|
||||
])
|
||||
return React.use(promise)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user