0.1.8 #11
@@ -12,9 +12,10 @@ export const LazyRefExtension = ReffuseExtension.make(() => ({
|
|||||||
const initialState = this.useMemo(() => ref, [], { doNotReExecuteOnRuntimeOrContextChange: true })
|
const initialState = this.useMemo(() => ref, [], { doNotReExecuteOnRuntimeOrContextChange: true })
|
||||||
const [reactStateValue, setReactStateValue] = React.useState(initialState)
|
const [reactStateValue, setReactStateValue] = React.useState(initialState)
|
||||||
|
|
||||||
this.useFork(() => Stream.runForEach(ref.changes, v => Effect.sync(() =>
|
this.useFork(() => Stream.runForEach(
|
||||||
setReactStateValue(v)
|
Stream.changes(ref.changes),
|
||||||
)), [ref])
|
v => Effect.sync(() => setReactStateValue(v)),
|
||||||
|
), [ref])
|
||||||
|
|
||||||
const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
||||||
LazyRef.update(ref, prevState =>
|
LazyRef.update(ref, prevState =>
|
||||||
|
|||||||
@@ -395,9 +395,10 @@ export abstract class ReffuseHelpers<R> {
|
|||||||
const initialState = this.useMemo(() => ref, [], { doNotReExecuteOnRuntimeOrContextChange: true })
|
const initialState = this.useMemo(() => ref, [], { doNotReExecuteOnRuntimeOrContextChange: true })
|
||||||
const [reactStateValue, setReactStateValue] = React.useState(initialState)
|
const [reactStateValue, setReactStateValue] = React.useState(initialState)
|
||||||
|
|
||||||
this.useFork(() => Stream.runForEach(ref.changes, v => Effect.sync(() =>
|
this.useFork(() => Stream.runForEach(
|
||||||
setReactStateValue(v)
|
Stream.changes(ref.changes),
|
||||||
)), [ref])
|
v => Effect.sync(() => setReactStateValue(v)),
|
||||||
|
), [ref])
|
||||||
|
|
||||||
const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
const setValue = this.useCallbackSync((setStateAction: React.SetStateAction<A>) =>
|
||||||
Ref.update(ref, prevState =>
|
Ref.update(ref, prevState =>
|
||||||
|
|||||||
Reference in New Issue
Block a user