-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve error message in Trans (#1880)
- Loading branch information
Showing
3 changed files
with
27 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import React from "react" | ||
|
||
import { useLingui } from "./I18nProvider" | ||
import { TransNoContext, TransProps } from "./TransNoContext" | ||
import { useLinguiInternal } from "./I18nProvider" | ||
import { TransNoContext, type TransProps } from "./TransNoContext" | ||
|
||
export function Trans(props: TransProps): React.ReactElement<any, any> | null { | ||
const lingui = useLingui() | ||
let errMessage = undefined | ||
if (process.env.NODE_ENV !== "production") { | ||
errMessage = `Trans component was rendered without I18nProvider. | ||
Attempted to render message: ${props.message} id: ${props.id}. Make sure this component is rendered inside a I18nProvider.` | ||
} | ||
const lingui = useLinguiInternal(errMessage) | ||
return React.createElement(TransNoContext, { ...props, lingui }) | ||
} |