page.mdx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { pageMetadata } from "@/lib/page-metadata"
  2. export const metadata = pageMetadata("docs/api/devtools-react")
  3. # @json-render/devtools-react
  4. React adapter for the json-render devtools. Drop-in `<JsonRenderDevtools />` component.
  5. See the [Devtools guide](/docs/devtools) for the drop-in walkthrough.
  6. ## JsonRenderDevtools
  7. ```tsx
  8. import { JsonRenderDevtools } from "@json-render/devtools-react";
  9. <JSONUIProvider registry={registry} handlers={handlers}>
  10. <Renderer spec={spec} registry={registry} />
  11. <JsonRenderDevtools spec={spec} catalog={catalog} messages={messages} />
  12. </JSONUIProvider>
  13. ```
  14. ### Props
  15. ```tsx
  16. interface JsonRenderDevtoolsProps {
  17. /** Current spec being rendered. */
  18. spec?: Spec | null;
  19. /** Catalog definition (required for the Catalog panel). */
  20. catalog?: Catalog | null;
  21. /** AI SDK useChat messages array. */
  22. messages?: readonly UIMessage[];
  23. /** Start the panel open. Default: false. */
  24. initialOpen?: boolean;
  25. /** Floating toggle position. */
  26. position?: "bottom-right" | "bottom-left" | "right";
  27. /** Toggle keybinding, or false to disable. Default: "mod+shift+j". */
  28. hotkey?: string | false;
  29. /** Ring buffer size. Default: 500. */
  30. bufferSize?: number;
  31. /** Fires for every devtools event. */
  32. onEvent?: (evt: DevtoolsEvent) => void;
  33. }
  34. ```
  35. In production builds the component renders `null`.
  36. ## useJsonRenderDevtools
  37. ```tsx
  38. import { useJsonRenderDevtools } from "@json-render/devtools-react";
  39. const devtools = useJsonRenderDevtools();
  40. devtools?.open();
  41. devtools?.toggle();
  42. devtools?.close();
  43. devtools?.clear();
  44. devtools?.recordEvent({ kind: "stream-text", at: Date.now(), text: "hi" });
  45. ```
  46. Access the running devtools instance from anywhere in the React tree. Returns `null` in production or before the component has mounted.