Skip to content

Use @usefractal/frac/web

This guide shows you how to use @usefractal/frac/web without @usefractal/frac/server to add React hooks and utilities to your views.

You should already have:

  • A working MCP server backend (in any technology)
  • Node.js 24+

Add frac to your project:

Terminal window
pnpm add @usefractal/frac

@usefractal/frac/web provides React hooks and utilities for building advanced Apps:

  • useLayout: Get the current user layout and visual environment information
  • useDisplayMode: Get and request view display mode changes
  • useRequestModal: Open a modal portaled outside of the view iframe
  • useUser: Get the session-stable user information (locale and userAgent)
  • useAppsSdkContext: Low-level hook to subscribe to window.openai state values
  • generateHelpers: Generate typed helpers for your views (requires @usefractal/frac/server)

Each hook is documented in the API Reference section in the sidebar.

Here’s a simple view using frac hooks:

src/views/my-view.tsx
import { useToolInfo } from "@usefractal/frac/web";
export default function MyView() {
const toolInfo = useToolInfo();
if (toolInfo.isPending) {
return <div>Loading...</div>;
}
if (toolInfo.isSuccess) {
return (
<div>
<h2>Results</h2>
<pre>{JSON.stringify(toolInfo.output.structuredContent, null, 2)}</pre>
</div>
);
}
return <div>No results</div>;
}

If you’re not using @usefractal/frac/server, you won’t get automatic type inference. You can still add types manually:

import { useToolInfo } from "@usefractal/frac/web";
interface MyToolInput {
query: string;
limit?: number;
}
export default function MyView() {
const toolInfo = useToolInfo<MyToolInput>();
// toolInfo.input is now typed as MyToolInput
console.log(toolInfo.input.query);
return <div>View content</div>;
}

To learn more about how to build an App, please read the Core Concepts and Interaction Model sections below.