React
Use prebuilt React components to add the Docs Embed to your React application
Steps
3
4
Add the GitBookFrame component
function App() {
return (
<GitBookProvider siteURL="https://docs.company.com">
<div className="app">
<YourAppContent />
<GitBookFrame
visitor={{
token: 'your-jwt-token', // Optional: for Adaptive Content or Authenticated Access
unsignedClaims: { userId: '123' } // Optional: custom claims for dynamic expressions
}}
/>
</div>
</GitBookProvider>
);
}5
Customize the embed
<GitBookProvider siteURL="https://docs.company.com">
<GitBookFrame
tabs={['assistant', 'docs']}
greeting={{ title: 'Welcome!', subtitle: 'How can I help?' }}
suggestions={['What is GitBook?', 'How do I get started?']}
actions={[
{
icon: 'circle-question',
label: 'Contact Support',
onClick: () => window.open('https://support.example.com', '_blank')
}
]}
tools={[/* ... */]}
visitor={{
token: 'your-jwt-token',
unsignedClaims: { userId: '123' }
}}
/>
</GitBookProvider>6
Control the embed with the useGitBook hook
import { useGitBook } from "@gitbook/embed/react";
function HelpButton() {
const gitbook = useGitBook();
const frameURL = gitbook.getFrameURL({ visitor: { token: '...' } });
const handleNavigate = () => {
const iframe = document.createElement('iframe');
iframe.src = frameURL;
const frame = gitbook.createFrame(iframe);
frame.navigateToPage('/getting-started');
frame.navigateToAssistant();
frame.postUserMessage('How do I get started?');
};
return <button onClick={handleNavigate}>Get Help</button>;
}7
8
Use with Next.js or server-side rendering
import dynamic from "next/dynamic";
const GitBookProvider = dynamic(
() => import("@gitbook/embed/react").then((mod) => mod.GitBookProvider),
{ ssr: false }
);
const GitBookFrame = dynamic(
() => import("@gitbook/embed/react").then((mod) => mod.GitBookFrame),
{ ssr: false }
);Props & Configuration
Prop
Type
Required
Default
Description
Prop
Type
Required
Default
Description
Configuration Options
tabs
tabsactions
actionsgreeting
greetingsuggestions
suggestionstools
toolsvisitor (Authenticated Access)
visitor (Authenticated Access)Common pitfalls
Last updated
Was this helpful?