This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Context, Effect, ExecutionStrategy, Exit, Fiber, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
||||
import { Context, Effect, ExecutionStrategy, Exit, Fiber, Option, Ref, Runtime, Scope, Stream, SubscriptionRef } from "effect"
|
||||
import React from "react"
|
||||
import * as ReffuseContext from "./ReffuseContext.js"
|
||||
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
||||
@@ -280,6 +280,17 @@ export class Reffuse<R> {
|
||||
return [reactStateValue, setValue]
|
||||
}
|
||||
|
||||
|
||||
useStreamState<A, E>(stream: Stream.Stream<A, E, R>): Option.Option<A> {
|
||||
const [reactStateValue, setReactStateValue] = React.useState(Option.none<A>())
|
||||
|
||||
this.useFork(Stream.runForEach(stream, v => Effect.sync(() =>
|
||||
setReactStateValue(Option.some(v))
|
||||
)), [stream])
|
||||
|
||||
return reactStateValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user