import { useMemo } from 'react' ; import { generateUID } from '@proton/components' ; import { range } from '@proton/shared/lib/helpers/array' ; import { Element } from '../models/element' ; export const PLACEHOLDER_ID_PREFIX = 'placeholder' ; export const usePlaceholders = ( inputElements , loading , expectedLength ) : Element [ ] => { const placeholders = useMemo ( ( ) => range ( 0 , expectedLength ) . map ( ( ) => ( { ID : generateUID ( PLACEHOLDER_ID_PREFIX ) } ) ) , [ loading , expectedLength ] ) ; const elements = useMemo ( ( ) => ( loading ? placeholders : ( inputElements as Element [ ] ) ) , [ loading , inputElements ] ) ; return elements ; } ;