0.1.0 #1
@@ -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 React from "react"
|
||||||
import * as ReffuseContext from "./ReffuseContext.js"
|
import * as ReffuseContext from "./ReffuseContext.js"
|
||||||
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
import * as ReffuseRuntime from "./ReffuseRuntime.js"
|
||||||
@@ -280,6 +280,17 @@ export class Reffuse<R> {
|
|||||||
return [reactStateValue, setValue]
|
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