useMemoSync
All checks were successful
Lint / lint (push) Successful in 10s

This commit is contained in:
Julien Valverdé
2025-01-19 01:32:26 +01:00
parent d070ebb903
commit 7ada793943

View File

@@ -98,16 +98,7 @@ export class Reffuse<R> {
return value
}
/**
* Reffuse equivalent to `React.useMemo`.
*
* `useMemo` will only recompute the memoized value by running the given synchronous effect when one of the deps has changed. \
* Trying to run an asynchronous effect will throw.
*
* Changes to the Reffuse runtime or context will recompute the value in addition to the deps.
* You can disable this behavior by setting `doNotReExecuteOnRuntimeOrContextChange` to `true` in `options`.
*/
useMemoUnscoped<A, E>(
useMemoSync<A, E>(
effect: Effect.Effect<A, E, R>,
deps?: React.DependencyList,
options?: RenderOptions,
@@ -280,15 +271,15 @@ export class Reffuse<R> {
useRef<A>(value: A): SubscriptionRef.SubscriptionRef<A> {
return this.useMemoUnscoped(
return this.useMemoSync(
SubscriptionRef.make(value),
[],
{ doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes
)
}
useRefFromEffect<A, E>(effect: Effect.Effect<A, E, R | Scope.Scope>): SubscriptionRef.SubscriptionRef<A> {
return this.useMemo(
useRefFromEffect<A, E>(effect: Effect.Effect<A, E, R>): SubscriptionRef.SubscriptionRef<A> {
return this.useMemoSync(
effect.pipe(Effect.flatMap(SubscriptionRef.make)),
[],
{ doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes