import { useMemo } from "react" ; import usePlaygroundContext from "./usePlaygroundContext" ; import { sep } from "@site/src/utils/path" ; import { COMPONENT_DIR , JS_EXT } from "../constants" ; export default function useComponentList ( ) { const { value : { files } } = usePlaygroundContext ( ) ; return useMemo ( ( ) => { const result = [ ] ; for ( const key of Object . keys ( files ) ) { if ( ! key . startsWith ( COMPONENT_DIR ) ) continue ; const name = key . substring ( COMPONENT_DIR . length ) ; if ( name . includes ( sep ) ) continue ; if ( ! name . endsWith ( JS_EXT ) ) continue ; result . push ( name . substring ( 0 , name . length - JS_EXT . length ) ) ; } return result . sort ( ) ; } , [ files ] ) ; }