react-code-dataset / next.js /packages /next /src /next-devtools /dev-overlay /utils /use-open-in-editor.ts
Download next.js/packages/next/src/next-devtools/dev-overlay/utils/use-open-in-editor.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 876 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/next-devtools/dev-overlay/utils/use-open-in-editor.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/next-devtools/dev-overlay/utils/use-open-in-editor.ts
-
curl -L -o use-open-in-editor.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/next-devtools/dev-overlay/utils/use-open-in-editor.ts
876 Bytes
| import { useCallback } from 'react' | |
| export function useOpenInEditor({ | |
| file, | |
| line1, | |
| column1, | |
| }: { | |
| file?: string | null | |
| line1?: number | null | |
| column1?: number | null | |
| } = {}) { | |
| const openInEditor = useCallback(() => { | |
| if (file == null || line1 == null || column1 == null) return | |
| const params = new URLSearchParams() | |
| params.append('file', file) | |
| params.append('line1', String(line1)) | |
| params.append('column1', String(column1)) | |
| self | |
| .fetch( | |
| `${ | |
| process.env.__NEXT_ROUTER_BASEPATH || '' | |
| }/__nextjs_launch-editor?${params.toString()}` | |
| ) | |
| .then( | |
| () => {}, | |
| (cause) => { | |
| console.error( | |
| `Failed to open file "${file} (${line1}:${column1})" in your editor. Cause:`, | |
| cause | |
| ) | |
| } | |
| ) | |
| }, [file, line1, column1]) | |
| return openInEditor | |
| } | |