# gt-next: General Translation Next.js SDK: Branch URL: https://generaltranslation.com/en-US/docs/next/api/components/branch.mdx --- title: Branch description: API reference for the Branch component --- {/* AUTO-GENERATED: Do not edit directly. Edit the template in content/docs-templates/ instead. */} ## Overview The `` component allows you to add conditional logic to a translation. ```jsx const status = 'active'; The user is active.

} inactive={

The user is inactive.

} /> ``` You pass a value to the `branch` parameter, and this gets matched with an output value based on the keys you provide. ## Reference ### Props The `[key]: string` syntax indicates arbitrary keys representing potential branches. For example, branches like `active` and `inactive` can be added as parameters. | Prop | Description | |------------|-----------------------------------------------------------------------------| | `branch` | The name of the branch to render. | | `children` | Fallback content to render if no matching branch is found. | | `[key]: string` | Branches representing possible content for the given branch value. Each key corresponds to a branch, and its value is the content to render. | ### Returns `JSX.Element` containing the content corresponding to the specified branch or the fallback content. ### Throws `Error` if the `branch` prop is not provided or is invalid. ## Examples ### Basic usage `` needs to have a different output for each possible value of the `branch` prop. In this example, the `user.hairColor` value is used to determine the output. We have defined props `black`, `brown`, and `blonde` to match the possible values of `user.hairColor`. ```jsx title="BranchExample.jsx" copy import { Branch } from 'gt-next'; export default function HairColor({ user }) { return ( Their hair is dark.

} brown="Their hair is in the middle." // (you can pass a string if you prefer) blonde={

Their hair is light.

} /> ); } ``` ### Fallback content The `children` will always be used as a fallback if no prop matches the value passed to `branch`. ```jsx title="BranchExample.jsx" copy import { Branch } from 'gt-next'; export default function HairColor({ user }) { return ( Their hair is dark.

} brown={

Their hair is in the middle.

} blonde={

Their hair is light.

} >

Their hair is unknown.

// [!code highlight]
); } ``` ### Translating Branch If you want to translate the content, simply wrap it in a `` component. ```jsx title="BranchExample.jsx" copy import { T, Branch } from 'gt-next'; export default function HairColor({ user }) { return ( // [!code highlight] Their hair is dark.

} brown={

Their hair is in the middle.

} blonde={

Their hair is light.

} >

Their hair is unknown.

// [!code highlight] ); } ``` ### Adding variables If you want to render dynamic values in the branch, make sure to wrap them in ``, ``, ``, or `` components. ```jsx title="BranchExample.jsx" copy import { Branch, T, Var } from 'gt-next'; export default function HairColor({ user }) { return ( Their hair is dark.

} brown={

Their hair is in the middle.

} blonde={

Their hair is light.

} >

Unhandled hair color: {user.hairColor}

// [!code highlight]
); } ``` --- ## Notes * The keys for branches can be any string value that matches the branch prop. This flexibility makes it easy to adapt `` to a wide range of use cases. * Combine `` with other components, such as `` for translations and [variable components](/docs/next/guides/variables) for dynamic content, to create rich and localized interfaces. ## Next steps * For more advanced usage and examples, refer to [Using Branching Components](/docs/next/guides/branches).