Skip to content

Tab Provider

A React context provider that manages and exposes the “current tab” state and the list of available modules/tabs.

  • Keeps track of the currently selected tab (module) in your UI.
  • Provides functions to switch between tabs.
  • Ensures components across your app can listen and respond to tab changes.
interface TabProviderProps {
children: React.ReactNode;
}
  • children: The wrapped components that will have access to the context.
import { TabProvider } from "@/context/TabProvider";
import MainView from "@/components/MainView";
function App() {
return (
<TabProvider>
<MainView />
</TabProvider>
);
}

Hook to access the current tab and available tab list, and to change tabs.

interface TabContextType {
currentTab: ModuleKey;
setCurrentTab: (key: ModuleKey) => void;
availableTabs: ModuleKey[];
}
  • currentTab: The active tab/module key (e.g., "home", "crm").
  • setCurrentTab(key): Switches the active tab to the given key.
  • availableTabs: List of all module keys registered in moduleRegistry.
import { useTabContext } from "@/context/TabProvider";
function ModuleTabsMenu() {
const { currentTab, setCurrentTab, availableTabs } = useTabContext();
return (
<nav>
{availableTabs.map((tabKey) => (
<button
key={tabKey}
onClick={() => setCurrentTab(tabKey)}
aria-pressed={currentTab === tabKey}
>
{tabKey === currentTab ? "🔹" : ""} {tabKey}
</button>
))}
</nav>
);
}

import { TabProvider, useTabContext } from "@/context/TabProvider";
function Sidebar() {
const { currentTab, setCurrentTab, availableTabs } = useTabContext();
return (
<ul>
{availableTabs.map((key) => (
<li key={key}>
<button
onClick={() => setCurrentTab(key)}
style={{
fontWeight: currentTab === key ? "bold" : "normal",
}}
>
{key.toUpperCase()}
</button>
</li>
))}
</ul>
);
}
function App() {
return (
<TabProvider>
<Sidebar />
<MainView />
</TabProvider>
);
}

  • TabProvider supplies the current tab key and a list of available module keys to descendants.
  • useTabContext() allows components to read the active tab and switch tabs easily.