Skip to content

Commit a9e8102

Browse files
fix: translation context default value check
1 parent 711e333 commit a9e8102

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

package/src/contexts/translationContext/TranslationContext.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ export type TranslationContextValue = {
2323
tDateTimeParser: TDateTimeParser;
2424
};
2525

26-
export const TranslationContext = React.createContext<TranslationContextValue>({
26+
const defaultTranslationContextValue: TranslationContextValue = {
2727
t: (key: string) => key,
2828
tDateTimeParser: (input) => Dayjs(input),
29-
});
29+
};
30+
31+
export const TranslationContext = React.createContext<TranslationContextValue>(
32+
defaultTranslationContextValue,
33+
);
3034

3135
export const TranslationProvider: React.FC<{
3236
value: TranslationContextValue;
@@ -37,7 +41,7 @@ export const TranslationProvider: React.FC<{
3741
export const useTranslationContext = () => {
3842
const contextValue = useContext(TranslationContext);
3943

40-
if (!contextValue && !isTestEnvironment()) {
44+
if (contextValue === defaultTranslationContextValue && !isTestEnvironment()) {
4145
throw new Error(
4246
`The useTranslationContext hook was called outside the TranslationContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider)(https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
4347
);

0 commit comments

Comments
 (0)