import { useMemo } from "react" ; import { useIntl , MessageDescriptor } from "react-intl" ; export function useFormatMessages < K extends string > ( messsages ) { const intl = useIntl ( ) ; return useMemo ( ( ) => Object . fromEntries ( Object . entries < MessageDescriptor > ( messsages ) . map ( ( [ id , message ] ) => [ id , intl . formatMessage ( message ) , ] ) ) , [ intl , messsages ] ) as any ; } if ( ! Object . fromEntries ) { Object . fromEntries = function < T > ( entries ) { return Array . from ( entries ) . reduce ( ( object , entry ) => Object . assign ( object , { [ entry [ 0 ] ] : entry [ 1 ] } , { } ) , { } ) ; } ; }