Skip to content

Instantly share code, notes, and snippets.

@vkbansal
Last active January 11, 2022 09:48
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/c7655ae813d903c62ba93b95308defc8 to your computer and use it in GitHub Desktop.
Save vkbansal/c7655ae813d903c62ba93b95308defc8 to your computer and use it in GitHub Desktop.
String Externalisation Snippets
// StringsContext.tsx
import { createContext } from "react";
// initialize the context
const StringsContext = createContext({});
// props for StringsContextProvider
export interface StringsContextProviderProps {
data: Record<string, any>;
}
// a wrapper for `StringsContext.Provider` for better API
export function StringsContextProvider(
props: React.PropsWithChildren<StringsContextProviderProps>
) {
return (
<StringsContext.Provider value={props.data}>
{props.children}
</StringsContext.Provider>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment