Download react-spring/docs/app/hooks/useCSB.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 745 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/hooks/useCSB.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/hooks/useCSB.ts
-
curl -L -o useCSB.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-spring/docs/app/hooks/useCSB.ts
745 Bytes
| import * as React from 'react' | |
| import { SANDBOXES } from '~/data/sandboxes' | |
| import { CodesandboxSandboxFetched, fetchSandbox } from '../helpers/sandboxes' | |
| export const useCSB = (sandboxTitles: Array<keyof typeof SANDBOXES>) => { | |
| const [sandboxes, setSandboxes] = React.useState<CodesandboxSandboxFetched[]>( | |
| [] | |
| ) | |
| React.useEffect(() => { | |
| const fetchSandboxes = async () => { | |
| const sandboxIds = sandboxTitles.map(title => { | |
| return SANDBOXES[title] | |
| }) | |
| const sandboxes = await Promise.all(sandboxIds.map(fetchSandbox)).then( | |
| boxes => boxes.sort((a, b) => a.title.localeCompare(b.title)) | |
| ) | |
| setSandboxes(sandboxes) | |
| } | |
| fetchSandboxes() | |
| }, [sandboxTitles]) | |
| return sandboxes | |
| } | |