Skip to content

Commit

Permalink
TranslatedField.js translations from TranslationContext can be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiash98 committed Feb 21, 2024
1 parent 906bbe4 commit d2151ca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/dak-components/lib/components/TranslatedField.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const getTranslationsData = async (lang, fields) => {

const useTranslation = (key) => {
const translations = useContext(TranslationContext);
if (translations === undefined) {
console.error(
"Missing translation for key " +
key +
" useContext(TranslationContext) is undefined"
);
return key; // default to render key if translations are not loaded
}
const item = translations[key];
if (!item) throw "Missing translation with key " + key;
return item;
Expand Down

0 comments on commit d2151ca

Please sign in to comment.