ntcore-ts / @ntcore-ts/react / useTopic
Function: useTopic()
Call Signature
useTopic<
T>(name,typeInfo,options?):UseTopicResult<T>
Defined in: react/src/lib/use-topic.ts:66
Subscribes to a NetworkTables topic and returns the latest value. Unsubscribes on unmount.
Reading only: Omit publish in options. You get { value, setValue: undefined, isReadyToWrite: false }.
Reading and writing: Pass publish: true or publish: { retained: true } (etc.) in options. You get { value, setValue, isReadyToWrite }. Only call setValue when isReadyToWrite is true.
Subscription is re-created only when nt, name, or typeInfo change. Optional options are read at subscribe time.
Type Parameters
T
T extends object
Parameters
name
string
Topic name (e.g. "/MyTable/Gyro").
typeInfo
[4, "json"]
Type info from NetworkTablesTypeInfos (e.g. NetworkTablesTypeInfos.kDouble).
options?
Optional defaultValue, subscribeOptions, and publish (make me the publisher).
Returns
.
Call Signature
useTopic<
T>(name,typeInfo,options?):UseTopicResult<T>
Defined in: react/src/lib/use-topic.ts:71
Subscribes to a NetworkTables topic and returns the latest value. Unsubscribes on unmount.
Reading only: Omit publish in options. You get { value, setValue: undefined, isReadyToWrite: false }.
Reading and writing: Pass publish: true or publish: { retained: true } (etc.) in options. You get { value, setValue, isReadyToWrite }. Only call setValue when isReadyToWrite is true.
Subscription is re-created only when nt, name, or typeInfo change. Optional options are read at subscribe time.
Type Parameters
T
T extends string | number | boolean | string[] | Uint8Array<ArrayBufferLike> | boolean[] | number[]
Parameters
name
string
Topic name (e.g. "/MyTable/Gyro").
typeInfo
Type info from NetworkTablesTypeInfos (e.g. NetworkTablesTypeInfos.kDouble).
options?
Optional defaultValue, subscribeOptions, and publish (make me the publisher).
Returns
.