0.1.1 #3

Merged
Thilawyn merged 24 commits from next into master 2025-01-22 03:42:22 +01:00
Showing only changes of commit a1703aae37 - Show all commits

View File

@@ -133,6 +133,29 @@ export class Reffuse<R> {
]) ])
} }
useMemoScoped<A, E>(
effect: Effect.Effect<A, E, R | Scope.Scope>,
deps?: React.DependencyList,
options?: RenderOptions & ScopeOptions,
): A {
const runSync = this.useRunSync()
const initialValue = React.useMemo(() => runSync(Effect.scoped(effect)), [])
const [value, setValue] = React.useState(initialValue)
React.useEffect(() => {
const scope = runSync(Scope.make(options?.finalizerExecutionStrategy))
setValue(runSync(Effect.provideService(effect, Scope.Scope, scope)))
return () => { runSync(Scope.close(scope, Exit.void)) }
}, [
...options?.doNotReExecuteOnRuntimeOrContextChange ? [] : [runSync],
...(deps ?? []),
])
return value
}
/** /**
* Reffuse equivalent to `React.useEffect`. * Reffuse equivalent to `React.useEffect`.
* *