useLastChanged
A hook that tracks when a source Observable last changed. Returns a read-only Observable containing the Date.now() timestamp of the most recent change, or null if the source has not changed yet.
Text input
—Type to update the text and track the last change timestamp.
Last changed
import { import useLastChanged
useLastChanged, import useObservable
useObservable } from "@usels/web";
function function Component(): JSX.Element
Component() { const const count$: any
count$ = import useObservable
useObservable(0); const const lastChanged$: any
lastChanged$ = import useLastChanged
useLastChanged(const count$: any
count$);
// null before any change, Date.now() timestamp after return <JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div>{const lastChanged$: any
lastChanged$.any
get()}</JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div>;}import { createLastChanged, observable } from "@usels/web";
function Component() { "use scope" const count$ = observable(0); const { timestamp$ } = createLastChanged(count$);
return <div>{timestamp$.get()}</div>;}initialValue — custom initial timestamp
Section titled “initialValue — custom initial timestamp”import { useLastChanged, useObservable } from "@usels/web";
function Component() { const count$ = useObservable(0); // Start with a known timestamp instead of null const lastChanged$ = useLastChanged(count$, Date.now());}import { createLastChanged, observable } from "@usels/web";
function Component() { "use scope" const count$ = observable(0); const { timestamp$ } = createLastChanged(count$, Date.now());}Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
source$ | Observable<T> | - Observable source value to watch. |
options | LastChangedOptions (optional) | - Configuration options. |
LastChangedOptions
Section titled “LastChangedOptions”Returns
Section titled “Returns”ReadonlyObservable<number \| null>
Observable reflecting the last-changed timestamp.