File size: 745 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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
}
|