Reference · React

useRecordQuery(query, options?)

Next release: this page describes techne-sdk/types, which is not in techne-sdk 0.3.4 yet. With techne-sdk 0.3 today shows the released API.

React hooktechne-sdk/reactIn the SDK, techne.query

One page of a query, as a React read. data is its items, typed by the query. useRecordQuery(Place.query(…)) answers places.

Use it inside <TechneProvider>. It is TanStack Query underneath. It caches, refetches on focus, and shares your app's QueryClient when there is one. Without one it keeps its own.

Parameters

NameTypeWhat it is
queryrequiredQuery<T>A pub.techne.draft.query, usually from a type's helper, e.g. Place.query({ text: { matches: 'cafe' } }). It types the items.
options.params{ [name]: string }The query's $param values, e.g. { here: '40.0150,-105.2705' }.
options.include'valid' | 'all''valid' (the default) answers only valid items. 'all' adds pending and invalid ones, with their problems.
options.limitnumberThe page size. It defaults to the query's limit, else the platform's 50.

Also cursor (the previous page's), count: true (the page gains count and capped), and enabled: false to hold the read.

Returns TanStack's query result, with the SDK's items

NameTypeWhat it is
dataValidItem<T>[] | undefinedThe page's items, in the query's order. undefined until the first answer. With include: 'all', Item<T>[].
pagePage<T> | undefinedThe whole page. It has items, cursor for the next one, and count and capped when asked.
isPendingbooleanTrue until there is data.
errorError | nullWhy the read failed, if it did.
refetch() => PromiseRead again now.

And the rest of TanStack's useQuery result (isLoading, isFetching, status, …). Its key starts ['techne', 'query', …] and ends with the viewer's DID, so invalidateQueries({ queryKey: ['techne'] }) refreshes every Techne read.

Each item

uriUri<T>The record's address.
cidstringThe version's content hash.
recordTThe record itself, e.g. a Place.
verdict'valid' | 'pending' | 'invalid'The SDK's own check of the record. Always 'valid' unless you ask for 'all'.
problemsstring[]Why it is not valid, or what it waits for. Empty when valid.
curatedbooleanA live curated record, composed from people's versions.
bylineByline | nullWhose version of a curated record speaks first, and where each field came from.
Cafes, then the next page

record is a Place. record.name and record.kind are typed from its lexicon.

The same read without React

useRecordQuery is useQuery(techne.queryOptions(query, options)), with data the page's items.

Calls pub.techne.draft.query.listRecords → once for each page