mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
18 lines
374 B
TypeScript
18 lines
374 B
TypeScript
import { useMemo } from 'react';
|
|
|
|
import { ERROR_LITERAL } from '~/constants/errors';
|
|
import { has } from '~/utils/ramda';
|
|
|
|
export const useTranslatedError = (error: string | undefined) => {
|
|
return useMemo(() => {
|
|
if (!error) {
|
|
return '';
|
|
}
|
|
|
|
if (!has(error, ERROR_LITERAL)) {
|
|
return error;
|
|
}
|
|
|
|
return ERROR_LITERAL[error];
|
|
}, [error]);
|
|
};
|