refactor(sdk-react): rename useDevice → useMeshDevice

Prevents collision with packages/web's own useDevice() Zustand hook. All
internal exports + tests updated; no behavior change.

Callers migrating off @meshtastic/core should use useMeshDevice() from
@meshtastic/sdk-react going forward.
This commit is contained in:
Dan Ditomaso
2026-04-23 22:33:43 -04:00
parent e2874ba16a
commit b94c4e608c
3 changed files with 13 additions and 7 deletions

View File

@@ -12,8 +12,8 @@ export { useMeshRegistry, useOptionalMeshRegistry } from "./src/adapters/useMesh
export { useSignal } from "./src/adapters/useSignal.ts";
export { useSignalValue } from "./src/adapters/useSignalValue.ts";
export { useDevice } from "./src/hooks/useDevice.ts";
export type { UseDeviceResult } from "./src/hooks/useDevice.ts";
export { useMeshDevice } from "./src/hooks/useMeshDevice.ts";
export type { UseMeshDeviceResult } from "./src/hooks/useMeshDevice.ts";
export { useConnection } from "./src/hooks/useConnection.ts";
export type { UseConnectionResult } from "./src/hooks/useConnection.ts";
export { useChat } from "./src/hooks/useChat.ts";

View File

@@ -3,7 +3,7 @@ import type { DeviceStatusEnum } from "@meshtastic/sdk";
import { useClient } from "../adapters/useClient.ts";
import { useSignal } from "../adapters/useSignal.ts";
export interface UseDeviceResult {
export interface UseMeshDeviceResult {
status: DeviceStatusEnum;
isConfigured: boolean;
myNodeNum: number | undefined;
@@ -12,7 +12,13 @@ export interface UseDeviceResult {
shutdown(seconds?: number): Promise<number>;
}
export function useDevice(): UseDeviceResult {
/**
* Exposes the device slice of the current MeshClient: status, metadata, and
* reboot/shutdown commands. Named `useMeshDevice` (not `useDevice`) so it does
* not collide with consumer hooks of the same name (e.g. the legacy one in
* `packages/web`).
*/
export function useMeshDevice(): UseMeshDeviceResult {
const client = useClient();
const status = useSignal(client.device.status);
const isConfigured = useSignal(client.device.isConfigured);

View File

@@ -3,7 +3,7 @@ import { MeshClient } from "@meshtastic/sdk";
import { createFakeTransport } from "@meshtastic/sdk/testing";
import { ChannelNumber } from "@meshtastic/sdk";
import { describe, expect, it } from "vitest";
import { MeshProvider, useChat, useDevice } from "../mod.ts";
import { MeshProvider, useChat, useMeshDevice } from "../mod.ts";
function setup() {
const handle = createFakeTransport();
@@ -15,9 +15,9 @@ function setup() {
}
describe("sdk-react hooks", () => {
it("useDevice re-renders on myNodeInfo", async () => {
it("useMeshDevice re-renders on myNodeInfo", async () => {
const { handle, wrapper } = setup();
const { result } = renderHook(() => useDevice(), { wrapper });
const { result } = renderHook(() => useMeshDevice(), { wrapper });
expect(result.current.myNodeNum).toBeUndefined();
await act(async () => {