Skip to content

react-rx@6.1.0

Choose a tag to compare

@squiggler-app squiggler-app released this 07 Sep 21:02
· 116 commits to current since this release
e276d8d

Minor Changes

  • #585 8fed462 Thanks @stipsan! - Add useObservableSubject, 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 RxJS Subject is 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)} />

    useObservableEvent is removed in v7. It is now implemented on top of useObservableSubject, which carries over to v7 unchanged, so call sites can be migrated on v6 and need no further changes after upgrading.

  • #582 27db7b6 Thanks @stipsan! - Deprecate the APIs that react-rx v7 removes, so editors and no-deprecated lint rules flag them ahead of the upgrade. Runtime behavior is unchanged.

    • useObservableEvent is removed in v7. Push events into a Subject you own and read the derived stream with useObservable or useSyncObservable.
    • Calling useObservable or useSyncObservable without an initialValue is removed in v7, where the argument is required. useObservable(observable$, undefined) keeps the v6 type and behavior. no-deprecated lint rules also flag uncalled references such as typeof 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 9010e04 Thanks @stipsan! - initialValue initializers are now resolved once per hook instance, like a useState initializer. They previously ran on every pre-emission getSnapshot read, so an initializer returning a fresh object (useObservable(obs$, () => ({...})), and the same on useSyncObservable) gave useSyncExternalStore a 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 in useSyncObservable's server snapshot.

    As with useState, the hook reads the initialValue argument 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.