import React from 'react' ; example function useInputDescribedBy ( { id , hasHelpText , hasError , } ) { return React . useMemo ( ( ) => { let errorId = null ; let helpTextId = null ; if ( id && hasError ) { errorId = `${ id }-error` ; } if ( id && hasHelpText ) { helpTextId = `${ id }-helptext` ; } return { describedBy : helpTextId || errorId ? { 'aria-describedby' : `${ helpTextId || '' } ${ errorId || '' }` . trim ( ) } : { } , helpTextId , errorId , } ; } , [ hasHelpText , hasError , id ] ) ; } export default useInputDescribedBy ;