useRemote
Reactive remote data binding powered by Legend-State’s sync engine.
Creates an Observable<T> that fetches from and optionally pushes to a remote source. No local persistence — data lives only in memory. Returns decomposed state including loading and error observables.
statusloading...
value0
Read-only
Section titled “Read-only”import { import useRemote
useRemote } from "@usels/web";
interface interface User
User { User.id: number
id: number; User.name: string
name: string;}
function function Component(): any
Component() { const { const data$: any
data$, const isLoaded$: any
isLoaded$, const error$: any
error$ } = import useRemote
useRemote<interface User
User | null>({ get: () => any
get: () => any
fetch("/api/user").any
then((r: any
r) => r: any
r.any
json()), initial: null
initial: null, });
return ( <any
div> {const error$: any
error$.any
get() ? ( <any
div>Error: {const error$: any
error$.any
get()?.any
message}</any
div> ) : const isLoaded$: any
isLoaded$.any
get() ? ( <any
div>{const data$: any
data$.any
get()?.any
name}</any
div> ) : ( <any
div>Loading...</any
div> )} </any
div> );}Read & write
Section titled “Read & write”import { import useRemote
useRemote } from "@usels/web";
function function Component(): any
Component() { const { const data$: any
data$, const refetch: any
refetch } = import useRemote
useRemote<{ count: number
count: number }>({ get: () => any
get: () => any
fetch("/api/counter").any
then((r: any
r) => r: any
r.any
json()), set: ({ value }: { value: any;}) => any
set: ({ value: any
value }) => any
fetch("/api/counter", { method: string
method: "PUT", body: any
body: any
JSON.any
stringify(value: any
value), }), initial: { count: number;}
initial: { count: number
count: 0 }, debounceSet: number
debounceSet: 500, });
return ( <any
div> <any
span>{const data$: any
data$.any
count.any
get()}</any
span> <any
button onClick: () => any
onClick={() => const data$: any
data$.any
count.any
set((c: any
c) => c: any
c + 1)}>+1</any
button> <any
button onClick: any
onClick={const refetch: any
refetch}>Refresh</any
button> </any
div> );}Type Declarations
Section titled “Type Declarations”export interface UseRemoteOptions<T> { get: () => Promise<T> | T; set?: (params: { value: T; changes: object[]; }) => Promise<void> | void; initial?: T; mode?: "set" | "assign" | "merge" | "append" | "prepend"; debounceSet?: number; transform?: { load?: (value: any) => T; save?: (value: T) => any; };}export interface UseRemoteReturn<T> { data$: Observable<T>; isLoaded$: ReadonlyObservable<boolean>; isFetching$: ReadonlyObservable<boolean>; error$: ReadonlyObservable<Error | undefined>; refetch: () => void;}export declare function useRemote<T>(options: UseRemoteOptions<T>): UseRemoteReturn<T>;Source
Section titled “Source”Contributors
Section titled “Contributors”- tigerwest
Changelog
Section titled “Changelog”a7392ab2026-03-06 - feat(core,browser): add sync strategy hooks (tigerwest)