# gt-react: General Translation React SDK: Static URL: https://generaltranslation.com/en-US/docs/react/api/components/static.mdx --- title: Static description: API reference for the Static component --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} ## Overview The `` component is used to handle sentence fragmentation and reusable content without sacrificing word agreement, conjugation, and word order changes. In the following example, two separate translations are created: "The beautiful boy plays with the ball" and "The beautiful girl plays with the ball". ```jsx function getSubject(gender) { return gender === 'male' ? 'boy' : 'girl'; } The beautiful {getSubject(gender)} plays with the ball. ; ``` The `` component tells the CLI tool to dereference a function call and catalog all possible content being returned by that function, treating every return statement as if it had a `` component wrapping it. **Advanced Usage:** The `` component is an advanced feature and should be used with caution as it can generate deceptively large numbers of translation entries. Furthermore, `` enforces a strict requirement that all possible content permutations must be statically analyzable. For more information, see the release notes for [gt-next@6.8.0](/blog/gt-next_v6_8_0). --- ## Reference ### Props ### Description | Prop | Description | | ---------- | -------------------------------------------------------------------------------------------------- | | `children` | Static content. The CLI tool will analyze all possible return values. | ### Returns `React.JSX.Element` containing the rendered content from the function call, with each possible outcome creating a separate translation entry. --- ## Behavior ### Build time analysis During the build process, the CLI tool analyzes the children of `` components and creates separate translation entries for each possible outcome. This enables proper grammatical agreement and word order handling across different languages. ### Requirements The children of `` components must be determinable at build time. The supported syntax includes: - String, number, and boolean literals - JSX expressions with nested `` and `` components - Ternary operators - Function invocations (that have statically analyzable outcomes) --- ## Examples ### Basic usage Use `` to handle dynamic content that affects sentence structure. ```jsx title="BasicExample.jsx" copy import { T, Static } from 'gt-react'; export default function Example({ gender }) { return ( The {gender === 'male' ? 'boy' : 'girl'} is beautiful. ); } ``` This creates two translation entries: - "The boy is beautiful" - "The girl is beautiful" ### With function invocations Use `` to handle dynamic content that affects sentence structure from a function invocation. ```jsx title="BasicExample.jsx" copy import { T, Static } from 'gt-react'; function getSubject(gender) { return gender === 'male' ? 'boy' : 'girl'; } export default function Example({ gender }) { return ( The {getSubject(gender)} is beautiful. ); } ``` ### With variables Combine `` with `` for dynamic content within static function returns. ```jsx title="WithVariables.jsx" copy import { T, Static, Var } from 'gt-react'; function getTitle(title) { return title === 'Mr.' ? 'Mr.' : 'Ms.'; } function getGreeting(title) { return ( <> Hello, {getTitle(title)}. How are you, {name}? ); } export default function Greeting({ title, name }) { return ( {getGreeting(title)} ); } ``` ### Multiple Static components Be careful when using multiple `` components as they multiply translation entries. ```jsx title="MultipleStatic.jsx" copy import { T, Static } from 'gt-react'; function getSubject(gender) { return gender === 'male' ? 'boy' : 'girl'; } function getObject(toy) { return toy === 'ball' ? 'ball' : 'crayon'; } export default function PlayExample({ gender, toy }) { return ( {getSubject(gender)} plays with the{' '} {getObject(toy)}. ); } ``` This creates four translation entries (2 × 2 combinations): - "boy plays with the ball" - "boy plays with the crayon" - "girl plays with the ball" - "girl plays with the crayon" ### Supported function syntax ```jsx title="SupportedSyntax.jsx" copy function getExamples(key) { switch (key) { case 'literals': if (condition1) { return 'The boy'; } else if (condition2) { return 22; } else { return true; } case 'jsx': return ( <> Hello, {getTitle(title)}. How are you,{' '} {name}? ); case 'ternary': return condition ? 'The boy' : 'The girl'; case 'function_calls': return otherStaticFunction(); } } ``` --- ## Limitations ### Performance impact Using `` can create exponential growth in translation entries. Each additional `` component multiplies the total number of translations. ### Variable content Any dynamic or variable content within static function returns must be wrapped in `` components. ```jsx // Correct function getContent() { return ( <> Hello, {userName}! ); } // Incorrect - will cause build errors function getContent() { return <>Hello, {userName}!; } ``` --- ## Notes - The `` component is designed for handling sentence fragmentation while maintaining grammatical accuracy across languages. - Always consider the performance implications of multiple `` components in a single translation. - Treat every return statement in static functions as if wrapped with a `` component. - Use `` judiciously - prefer simpler translation structures when possible. ## Next steps - For variable content within translations, see the [``](/docs/react/api/components/var) component. - For the main translation component, see [``](/docs/react/api/components/t). - For the string equivalent of ``, see [`declareStatic`](/docs/react/api/strings/declare-static).