Use prebuilt React components to add the Docs Embed to your React application
For React projects, GitBook provides prebuilt components that make embedding your docs simple and idiomatic. The components handle state management, context, and lifecycle automatically.
Place the frame component where you want the embed to appear:
functionApp(){return (<GitBookProvidersiteURL="https://docs.company.com"><divclassName="app"><YourAppContent/><GitBookFramevisitor={{token:'your-jwt-token',// Optional: for Adaptive Content or Authenticated AccessunsignedClaims:{userId:'123'}// Optional: custom claims for dynamic expressions}}/></div></GitBookProvider> );}
5
Customize the embed
Pass configuration props to the frame component:
<GitBookProvidersiteURL="https://docs.company.com"><GitBookFrametrademark={false}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
Use the useGitBook hook to interact with the embed programmatically:
import{useGitBook}from"@gitbook/embed/react";functionHelpButton(){constgitbook=useGitBook();constframeURL=gitbook.getFrameURL({visitor:{token:'...'}});consthandleNavigate=()=>{constiframe=document.createElement('iframe');iframe.src=frameURL;constframe=gitbook.createFrame(iframe);frame.navigateToPage('/getting-started');frame.navigateToAssistant();frame.postUserMessage('How do I get started?');};return<buttononClick={handleNavigate}>Get Help</button>;}