### Start Create React App example Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Navigate to the Create React App example directory and start the development server. ```shell cd apps/cra pnpm start ``` -------------------------------- ### Start Next.js example Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Navigate to the Next.js example directory and start the development server. ```shell cd apps/next pnpm dev ``` -------------------------------- ### Install project dependencies with pnpm Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Install all necessary project dependencies using the pnpm package manager. ```shell pnpm install ``` -------------------------------- ### Install click-to-react-component with npm Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Install the package using npm. It will be automatically removed from production builds due to tree-shaking. ```shell npm install click-to-react-component ``` -------------------------------- ### Run Next.js Development Server Source: https://github.com/ericclemmons/click-to-component/blob/main/apps/next/README.md Execute these commands to start the local development server for your Next.js application. Open your browser to http://localhost:3000 to view the application. ```bash npm run dev ``` ```bash yarn dev ``` -------------------------------- ### Install click-to-react-component with pnpm Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Install the package using pnpm. It will be automatically removed from production builds due to tree-shaking. ```shell pnpm add click-to-react-component ``` -------------------------------- ### Configure Docusaurus for Click-to-Component Source: https://context7.com/ericclemmons/click-to-component/llms.txt Install the Babel plugin and configure `babel.config.js` to enable `_debugSource` for development builds. This setup is required for click-to-react-component to function correctly. ```javascript // Install dependency: // npm install @babel/plugin-transform-react-jsx-source // babel.config.js module.exports = { presets: [require.resolve('@docusaurus/core/lib/babel/preset')], plugins: [ ...(process.env.BABEL_ENV === 'development' ? ['@babel/plugin-transform-react-jsx-source'] : []), ], } ``` ```javascript // src/theme/Root.js import { ClickToComponent } from 'click-to-react-component' import React from 'react' export default function Root({ children }) { return ( <> {children} ) } ``` -------------------------------- ### Install click-to-react-component with yarn Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Install the package using yarn. It will be automatically removed from production builds due to tree-shaking. ```shell yarn add click-to-react-component ``` -------------------------------- ### Configure Docusaurus for ClickToComponent Source: https://github.com/ericclemmons/click-to-component/blob/main/packages/click-to-react-component/README.md Install the necessary Babel plugin and configure your Docusaurus root component to include ClickToComponent for source navigation. ```js module.exports = { presets: [require.resolve('@docusaurus/core/lib/babel/preset')], plugins: [ ...(process.env.BABEL_ENV === 'development' ? ['@babel/plugin-transform-react-jsx-source'] : []), ], }; ``` ```js import { ClickToComponent } from 'click-to-react-component'; import React from 'react'; // Default implementation, that you can customize export default function Root({ children }) { return ( <> {children} ); } ``` -------------------------------- ### Get Ancestor Fibers with getReactInstancesForElement Source: https://context7.com/ericclemmons/click-to-component/llms.txt Walks the React Fiber tree upward from a DOM element, collecting all ancestor Fibers into an array. This generates the component hierarchy for context menus. ```javascript import { getReactInstancesForElement } from 'click-to-react-component/src/getReactInstancesForElement.js' const el = document.querySelector('.product-card') const instances = getReactInstancesForElement(el) instances.forEach((fiber) => { const source = fiber._debugSource if (source) { console.log(`${fiber.type?.name} → ${source.fileName}:${source.lineNumber}`) } }) // ProductCard → src/components/ProductCard.tsx:5 // ProductList → src/pages/Shop.tsx:22 // ShopPage → src/pages/Shop.tsx:1 // App → src/App.tsx:8 ``` -------------------------------- ### Get Element Source with Fallback Source: https://context7.com/ericclemmons/click-to-component/llms.txt Looks up the source code location for a given DOM element. It first tries to find the direct Fiber for the element and, if that fails, walks up the DOM tree to find an ancestor with source information. Useful for elements like text nodes or host elements that don't directly correspond to user-defined React components. Throws an error if no parent with source info is found. ```typescript import { getSourceForElement } from 'click-to-react-component/src/getSourceForElement.js' // Direct component element — returns immediately const source1 = getSourceForElement(document.querySelector('.button')) // → { fileName: 'src/Button.tsx', lineNumber: 7, columnNumber: 2 } // Deeply nested span inside a component — climbs to nearest component const source2 = getSourceForElement(document.querySelector('span.label')) // → { fileName: 'src/Label.tsx', lineNumber: 3, columnNumber: 4 } // If no ancestor has source info, throws Error('No parent found for element') ``` -------------------------------- ### Get Serializable Component Props Source: https://context7.com/ericclemmons/click-to-component/llms.txt Extracts scalar props (string, number, boolean, symbol) from a React Fiber's `memoizedProps`. It filters out `key`, children, functions, and props matching the component's `defaultProps`. The result is used for hoverable tooltips in the component list. ```typescript import { getPropsForInstance } from 'click-to-react-component/src/getPropsForInstance.js' // Given a Fiber for: