React
Use prebuilt React components to add the Docs Embed to your React application
Last updated
Was this helpful?
Use prebuilt React components to add the Docs Embed to your React application
Last updated
Was this helpful?
Was this helpful?
@gitbook/embed to your React project:For the complete API reference and source code, see the @gitbook/embed package on GitHub.
GitBookProvider Props:
siteURL
string
Yes
N/A
Your GitBook docs site URL (e.g., https://docs.company.com).
children
ReactNode
Yes
N/A
Child components to render within the provider.
GitBookFrame Props:
All configuration options can be passed as props to <GitBookFrame>. See the Configuration section below for available options.
className
string
No
null
CSS class name to apply to the frame container.
style
object
No
{}
Inline styles to apply to the frame container.
useGitBook Hook:
Returns a GitBookClient instance with the following methods:
getFrameURL(options?: { visitor?: {...} }) β string - Get the iframe URL
createFrame(iframe: HTMLIFrameElement) β GitBookFrameClient - Create a frame client
The frame client provides:
navigateToPage(path: string) β void
navigateToAssistant() β void
postUserMessage(message: string) β void
clearChat() β void
configure(settings: {...}) β void
on(event: string, listener: Function) β () => void
Configuration options are available as props on <GitBookFrame>:
Override which tabs are displayed. Defaults to your site's configuration.
Type: ('assistant' | 'docs')[]
Custom action buttons rendered in the sidebar alongside tabs. Each action button triggers a callback when clicked.
Note: This was previously named buttons. Use actions instead.
Type: Array<{ icon: string, label: string, onClick: () => void }>
Welcome message displayed in the Assistant tab.
Type: { title: string, subtitle: string }
Suggested questions displayed in the Assistant welcome screen.
Type: string[]
Custom AI tools to extend the Assistant. See Creating custom tools for details.
Type: Array<{ name: string, description: string, inputSchema: object, execute: Function, confirmation?: {...} }>
Used for Adaptive Content and Authenticated Access.
Type: { token?: string, unsignedClaims?: Record<string, unknown> }
Not wrapping with GitBookProvider β The GitBookFrame requires a parent GitBookProvider to function.
Using with SSR without dynamic import β The component uses browser APIs and must be dynamically imported in Next.js or other SSR frameworks.
siteURL not matching published docs β Ensure the siteURL prop matches your live docs site URL exactly.
Calling useGitBook outside provider β The useGitBook hook must be used within a component that's a child of GitBookProvider.
Multiple providers in the tree β Avoid nesting multiple GitBookProvider instances, as this can cause context conflicts.
Using old component names β The component is now GitBookFrame, not GitBookAssistantFrame.
npm install @gitbook/embedvisitor
object
No
{}
Authenticated access options (see below).