Created
March 26, 2022 17:43
-
-
Save nemrosim/b3e12ed884b390b81d349164f62d2e48 to your computer and use it in GitHub Desktop.
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
import React from "react"; | |
import { Trans } from "@lingui/macro"; | |
import { TransRenderProps } from "@lingui/react"; | |
const RenderProps: React.FC<TransRenderProps> = ({ id, translation }) => { | |
if (translation) { | |
return ( | |
<> | |
{translation} | |
</> | |
); | |
} | |
return ( | |
<> | |
{id} | |
</> | |
); | |
} | |
export const TransPropsExample: React.FC = () => { | |
const getSomeValue = () => { | |
return 25 | |
} | |
return ( | |
<Trans | |
comment='This message in an example without any context' | |
/* | |
NOTE: | |
1. will not pass TransRenderProps | |
2. You can't use component with render prop - choose | |
*/ | |
// component={RenderProps} // NOTE: will not pass TransRenderProps | |
render={RenderProps} | |
values={{ | |
name: 'hello' | |
}} | |
>A message that makes no sense. Value: {getSomeValue()}</Trans> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment