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