Skip to content

ntcore-ts / @ntcore-ts/react / useProtobufTopic

Function: useProtobufTopic()

useProtobufTopic<T>(name, options?): UseProtobufTopicResult<T>

Defined in: react/src/lib/use-protobuf-topic.ts:57

Subscribes to a NetworkTables protobuf topic and returns the latest decoded 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 or name change. Optional options are read at subscribe time.

Type Parameters

T

T extends object

Parameters

name

string

Topic name (e.g. "/MyTable/Pose").

options?

UseProtobufTopicOptions<T>

Optional defaultValue, validator, protoFilePath, protoSource, messageType, subscribeOptions, publish.

Returns

UseProtobufTopicResult<T>

.

Released under the MIT License.