Repository navigation
react-rx@6.1.0
Minor Changes
-
#585
8fed462Thanks @stipsan! - AdduseObservableSubject, a hook that returns the two halves of an event: an observable of the values pushed into it, and a referentially stable handler that pushes them. The underlying RxJSSubjectis scoped to the component instance and only its observable side is exposed.const [events$, handleEvent] = useObservableSubject<string>() const value$ = useMemo(() => events$.pipe(map(Number)), [events$]) const value = useSyncObservable(value$, 1) // <input value={value} onChange={(event) => handleEvent(event.currentTarget.value)} />
useObservableEventis removed in v7. It is now implemented on top ofuseObservableSubject, which carries over to v7 unchanged, so call sites can be migrated on v6 and need no further changes after upgrading. -
#582
27db7b6Thanks @stipsan! - Deprecate the APIs that react-rx v7 removes, so editors andno-deprecatedlint rules flag them ahead of the upgrade. Runtime behavior is unchanged.useObservableEventis removed in v7. Push events into aSubjectyou own and read the derived stream withuseObservableoruseSyncObservable.- Calling
useObservableoruseSyncObservablewithout aninitialValueis removed in v7, where the argument is required.useObservable(observable$, undefined)keeps the v6 type and behavior.no-deprecatedlint rules also flag uncalled references such astypeof useObservable, because they read the tags of every overload. Those are false positives. Suppress them locally.
See the v6 to v7 migration guide.
Patch Changes
-
#579
9010e04Thanks @stipsan! -initialValueinitializers are now resolved once per hook instance, like auseStateinitializer. They previously ran on every pre-emissiongetSnapshotread, so an initializer returning a fresh object (useObservable(obs$, () => ({...})), and the same onuseSyncObservable) gaveuseSyncExternalStorea new snapshot reference on every consistency check and looped until React aborted with "Maximum update depth exceeded". The resolved value is now cached per instance, which also makes the pre-emission snapshot reference stable across re-renders and fixes the equivalent hazard inuseSyncObservable's server snapshot.As with
useState, the hook reads theinitialValueargument on its first render only. A different value passed on a later render is ignored until the hook remounts, where a plain value used to be re-read on every pre-emission render. Keep initializers pure. React Strict Mode calls them twice in development and keeps one result.