Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

746 B
Raw Blame
import { useEffect, useState } from 'react';

/** Load a selected graph record without rendering a previous selection's detail. */
export default function useGraphNodeDetail(selectionKey, loader, recordId) {
  const [detail, setDetail] = useState(null);

  useEffect(() => {
    let active = true;
    setDetail(null);
    if (selectionKey != null && loader) {
      Promise.resolve().then(() => loader(recordId)).then(record => {
        if (active) setDetail({ key: selectionKey, record });
      }).catch(() => {
        if (active) setDetail(null);
      });
    }
    return () => { active = false; };
  }, [selectionKey, loader, recordId]);

  return selectionKey != null && loader && detail?.key === selectionKey ? detail.record : null;
}