diff --git a/packages/reffuse/src/Reffuse.ts b/packages/reffuse/src/Reffuse.ts index aaee1ae..e87c891 100644 --- a/packages/reffuse/src/Reffuse.ts +++ b/packages/reffuse/src/Reffuse.ts @@ -98,16 +98,7 @@ export class Reffuse { 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( + useMemoSync( effect: Effect.Effect, deps?: React.DependencyList, options?: RenderOptions, @@ -280,15 +271,15 @@ export class Reffuse { useRef(value: A): SubscriptionRef.SubscriptionRef { - return this.useMemoUnscoped( + return this.useMemoSync( SubscriptionRef.make(value), [], { doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes ) } - useRefFromEffect(effect: Effect.Effect): SubscriptionRef.SubscriptionRef { - return this.useMemo( + useRefFromEffect(effect: Effect.Effect): SubscriptionRef.SubscriptionRef { + return this.useMemoSync( effect.pipe(Effect.flatMap(SubscriptionRef.make)), [], { doNotReExecuteOnRuntimeOrContextChange: false }, // Do not recreate the ref when the context changes