Created
January 11, 2022 09:53
-
-
Save vkbansal/ff128cd66627312b13f12d02c849a19a to your computer and use it in GitHub Desktop.
string-ext-08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// StringsContext.tsx | |
+ import has from "lodash.has"; | |
+ import get from "lodash.get"; | |
export function useLocaleStrings() { | |
const strings = useStringsContext(); | |
return { | |
getString(key: string): string { | |
- if (key in strings) { | |
+ if (has(strings, key)) { | |
- return strings[key]; | |
+ return get(strings, key); | |
} | |
throw new Error( | |
`Strings data does not have a definition for: "${key}"` | |
); | |
} | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment