// src/App.jsx import { createContext, useContext, useState } from "react"; const TabsContext = createContext(null); function Tabs({ children }) { const [activeTab, setActiveTab] = useState(0); return ( {children} ); } function Tab({ index, children }) { const { activeTab, setActiveTab } = useContext(TabsContext); return ( ); } function Panel({ index, children }) { const { activeTab } = useContext(TabsContext); return activeTab === index ?
{children}
: null; } Tabs.Tab = Tab; Tabs.Panel = Panel; function App() { return ( Profile Settings Billing Profile content Settings content Billing content ); } export default App; /* Notes: - Tab and Panel never receive activeTab as a prop directly — both read it from TabsContext, set up entirely inside Tabs itself. - Only the Panel whose index matches the current activeTab renders its children; the other two return null. */