Files
backnotprop__plannotator/packages/ui/config/useConfig.ts
Michael Ramos 401793e35f feat: custom display name + config file foundation (#399)
Adds user-editable display names and persistent config via ~/.plannotator/config.json.

- ConfigStore singleton with precedence: server config file > cookie > default
- Editable identity input in Settings with "Use git name" and regenerate buttons
- POST /api/config endpoint for write-back across all 6 servers
- getServerConfig() reads config fresh per request (no stale cache)
- Eager constructor hydration so the store is safe to read before init()
- vendor.sh as single source of truth for Pi extension vendoring
- Vendor parity test to prevent missing generated modules

Closes #396
2026-03-26 11:54:22 -07:00

21 lines
764 B
TypeScript

/**
* React hook for consuming ConfigStore values.
*
* Uses useSyncExternalStore for concurrent-mode-safe subscriptions
* to the singleton configStore — no context provider needed.
*/
import { useCallback, useSyncExternalStore } from 'react';
import { configStore, type SettingValue } from './configStore';
import type { SettingName } from './settings';
/** Read a config value reactively. Re-renders when the store changes. */
export function useConfigValue<K extends SettingName>(key: K): SettingValue<K> {
const subscribe = useCallback(
(onStoreChange: () => void) => configStore.subscribe(onStoreChange),
[],
);
const getSnapshot = useCallback(() => configStore.get(key), [key]);
return useSyncExternalStore(subscribe, getSnapshot);
}