import { useMemo } from "react" ; import usePlaygroundContext from "./usePlaygroundContext" ; import { sep } from "@site/src/utils/path" ; import { ENVIRONMENT_DIR } from "../constants" ; export default function useEnvironmentList ( ) { const { value : { files } } = usePlaygroundContext ( ) ; return useMemo ( ( ) => { const result = { } ; for ( const key of Object . keys ( files ) ) { if ( ! key . startsWith ( ENVIRONMENT_DIR ) ) continue ; const [ name , ... rest ] = key . substring ( ENVIRONMENT_DIR . length ) . split ( sep ) ; if ( ! rest . length ) continue ; result [ name ] = true ; } return Object . keys ( result ) . sort ( ) ; } , [ files ] ) ; }