Skip to content
Reactivity

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 { 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());
}
ParameterTypeDescription
source$Observable<T>- Observable source value to watch.
optionsLastChangedOptions (optional)- Configuration options.
OptionTypeDefaultDescription
initialValuenumber | nullnullInitial timestamp value.

ReadonlyObservable<number \| null>

Observable reflecting the last-changed timestamp.

View on GitHub