Skip to content

Instantly share code, notes, and snippets.

@vkbansal
Created January 11, 2022 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkbansal/26dc10c5bda51e2dd0502134edd7ff20 to your computer and use it in GitHub Desktop.
Save vkbansal/26dc10c5bda51e2dd0502134edd7ff20 to your computer and use it in GitHub Desktop.
// StringsContext.tsx
export interface LocaleStringProps extends React.HTMLAttributes<any> {
strKey: string;
as?: keyof JSX.IntrinsicElements;
}
export function LocaleString(props: LocaleStringProps): React.ReactElement {
const { strKey, as, ...rest } = props;
const { getString } = useLocaleStrings();
const Component = as || "span";
return <Component {...rest}>{getString(strKey)}</Component>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment