useOrgChartContext

A hook that provides access to the OrgChartModel which has various functions that can be used to interact with the OrgChart. It can only be used inside an OrgChart component or an OrgChartProvider.

 function OrgChartWrapper() {
   const { fitContent, zoomToItem } = useOrgChartContext()

   return (
     <>
       <OrgChart data={data} contextMenuItems={(item: CustomOrgChartItem | null) => {
           if (item) {
             return [{ title: 'Zoom to Item', action: () => item && zoomToItem(item) }]
           }
           return []
         }}>
       </OrgChart>
       <Sidebar>
         <button onClick={fitContent}>Fit Content</button>
       </Sidebar>
     </>
   )
 }

 function OrganizationChart () {
   return (
     <OrgChartProvider>
       <OrgChartWrapper></OrgChartWrapper>
     </OrgChartProvider>
   )
 }

Returns

TypeDescription
OrgChartModel
Returns the OrgChartModel used in this context.