Skip to content

Instantly share code, notes, and snippets.

@nemrosim
Created March 26, 2022 17:43
Show Gist options
  • Save nemrosim/b3e12ed884b390b81d349164f62d2e48 to your computer and use it in GitHub Desktop.
Save nemrosim/b3e12ed884b390b81d349164f62d2e48 to your computer and use it in GitHub Desktop.
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