This commit is contained in:
@@ -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`.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user