Skip to content

Instantly share code, notes, and snippets.

@vkbansal
Created January 11, 2022 09:53
Show Gist options
  • Save vkbansal/ff128cd66627312b13f12d02c849a19a to your computer and use it in GitHub Desktop.
Save vkbansal/ff128cd66627312b13f12d02c849a19a to your computer and use it in GitHub Desktop.
string-ext-08
// 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