Skip to content

useRos

Reads the shared ROS connection and its live status from the nearest RosProvider.

tsx
import { useRos } from "roshooks";

const { ros, status, isConnected, error } = useRos();

Returns

FieldTypeDescription
rosRosThe underlying roslib.js connection handle. Use it for low-level APIs not covered by a Hook (getTopics, getServices, getParams, ...).
status"connecting" | "connected" | "closed" | "error"The connection's current state.
isConnectedbooleanShorthand for status === "connected".
errorunknownThe most recent connection error, or null.

Example

tsx
function ConnectionBadge() {
  const { status } = useRos();
  return <span>{status}</span>;
}

See Connection Status for a full breakdown of the state machine.

WARNING

Throws if there's no RosProvider above the calling component in the tree.

Released under the BSD-3 License.