useObservable

Reads an Observable the way a SwiftUI body does: the component re-renders only when a property it read changes. Pass the object from props, state or anywhere else.

Declaration

React
function useObservable<T extends Observable>(
  object: T
): Bindable<T>

Parameters

  • object*T

Discussion

@example const [library] = useState(() => new Library()); const { count } = useObservable(library);

See also

More in Hooks.