MDK Logo

UI Core

Framework-agnostic headless state for the MDK App Toolkit — Zustand stores and a TanStack QueryClient factory

@tetherto/mdk-ui-core

If you are building a React app with the MDK kit, start with the React adapter instead. <MdkProvider> and adapter hooks such as useAuth and useDevices wrap this package so most React code never imports @tetherto/mdk-ui-core directly.

Use this reference when you need headless store access outside React (logging, websocket setup, test helpers) or when authoring a future framework adapter.

@tetherto/mdk-ui-core is the framework-agnostic headless layer of the MDK App Toolkit. It ships Zustand vanilla stores and a TanStack Query Core QueryClient factory. There are no React imports in this package.

Subpath exports

SubpathPurpose
.Top-level barrel
./storeZustand vanilla stores
./queryQueryClient factory, query keys, and query/mutation factories
./typesShared type contracts
./stores.jsonMachine-readable store manifest (generated at build time)

Stores

Each store is a Zustand vanilla singleton. In a React app, read and update state through the matching adapter hook instead of importing stores directly.

StoreSummaryAdapter hook
authStoreSession token and permission payloaduseAuth
devicesStoreFleet device list and current selectionuseDevices
timezoneStoreActive operator timezoneuseTimezone
notificationStoreUnread notification counter (count, increment, decrement, reset)useNotifications
actionsStorePending device and pool action submissionsuseActions

Import from @tetherto/mdk-ui-core/store (or the top-level barrel).

QueryClient factory

createMdkQueryClient builds a TanStack Query Core client with environment-aware App Node base URL resolution:

  1. Explicit override (typically from <MdkProvider>)
  2. Build-time env: VITE_MDK_API_URL (Vite) or MDK_API_URL (Node)
  3. Default: http://localhost:3000

The ./query subpath also exports query key helpers and factories (authQuery, devicesQuery, deviceQuery, telemetryQuery). See TanStack Query for general usage.

Headless read outside React

Utility code can subscribe to a store without React:

import { authStore } from '@tetherto/mdk-ui-core/store'

const token = authStore.getState().token

const unsubscribe = authStore.subscribe((state) => {
  console.log('token changed', state.token)
})

// later: unsubscribe()

<MdkProvider> wires these singleton stores into React and creates the shared QueryClient for adapter hooks.

What's not here yet

Headless primitives will include throttled telemetry subscriptions, stale detection, history ring buffers, and an optimistic command state machine. They ship alongside the consuming code that needs them.

Next steps

On this page