Last active
January 11, 2022 09:46
-
-
Save vkbansal/239ad3d118b6b93708f265baf2539480 to your computer and use it in GitHub Desktop.
string-ext-06
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 | |
export function useStringsContext(): Record<string, any> { | |
return React.useContext(StringsContext); | |
} | |
export interface UseLocaleStringsReturn { | |
getString(key: string): string; | |
} | |
export function useLocaleStrings() { | |
const strings = useStringsContext(); | |
return { | |
getString(key: string): string { | |
if (key in strings) { | |
return 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