Exports
Constants, helpers, hooks, components, and types
Import core utilities from tamagui or @tamagui/core. Ref utilities are
also available from @tamagui/element.
Constants
Constants are re-exported from @tamagui/constants:
isWeb: true if targeting the web (true for SSR and client)isBrowser: true when bothnavigatorandlocationare definedisServer:isWeb && !isBrowserisClient:isWeb && isBrowserisChrome: client-side ChromeisWebTouchable: web-only touch device (client side only)isTouchable: true on native or touch-capable web clients
Helpers
getConfig
getConfig returns your fully parsed Tamagui config. It avoids the circular
imports that come with importing the config directly. Prefer useTheme for
themes and getTokens/getToken/getTokenValue for tokens, and use this for
other parts of the config.
insertFont
Adds a new font after the initial createTamagui call. GenericFont matches a
font passed to createTamagui, and ParsedFont is the font with subkeys
turned into variable objects.
updateFont
The same as insertFont, but will update an existing font.
isTamaguiComponent
If no name given, true if a Tamagui component, if name given ensures it’s the specific named Tamagui component.
isTamaguiElement
If no name given, true if a Tamagui ReactElement, if name given ensures it’s the specific named Tamagui component element.
getTokens
Returns the parsed Tamagui config object of all your tokens, can be used at
runtime to get values from tokens. If you are looking to get a single token
value, prefer getToken or getTokenValue.
getToken
Given the specific name of a token or a name + group, will return the value as
either a variable on the web, or raw value on native. So if you define a size
token with key small and value of 14:
getTokenValue
Similar to getToken, but always returns the raw value rather than the variable
name. If you define a size token with key small and value of 14:
getVariable
Accepts a Variable from a parsed theme or token (returned by
createTamagui, useTheme, or getTokens).
Calling getVariable(useTheme().color) returns var(--color) on web, and
#fff on other platforms.
splitStyleProps
splitStyleProps partitions an object in one pass and returns
[selectedProps, remainingProps]. With no options, the first object contains
style props and the second contains everything else. Props keep their authored
keys by default. It is exported from @tamagui/core, @tamagui/ui, and
tamagui:
Pass expandShorthands: true to write selected shorthand props under their
canonical keys:
A filter map selects only its canonical keys. Style props excluded by the map remain in the second object. This also lets a component intentionally select non-style behavior props:
For dynamic rules, filter can be a callback. It receives the canonical key,
the value, the original authored key, and whether the canonical key is a known
style prop:
Filter maps infer the selected keys precisely. A callback can return a type
predicate on originalKey when its rule narrows to a known key union.
getWebElement
A runtime utility that narrows a TamaguiElement to an HTMLElement. Throws if
the element is not an HTMLElement. Useful for platform-specific code where you
know you’re on web.
Hooks
See useMedia for media queries and useTheme for theme values.
useIsomorphicLayoutEffect
Uses useEffect on the server and useLayoutEffect on the client to avoid
layout effect warnings during server rendering.
useWebRef
For platform-specific files (.tsx and .native.tsx), this hook creates a
properly typed ref for web that also composes with a forwarded ref. When you
need to access HTMLElement-specific properties like selectionStart on
inputs, this avoids needing any casts.
useNativeRef
For platform-specific files (.native.tsx), this hook creates a properly typed
ref for React Native that also composes with a forwarded ref. Pairs with
useWebRef for cross-platform component development.
For input components, use useNativeInputRef which types to TextInput:
useThemeName
Returns the string name of the current theme.
useIsTouchDevice
SSR-friendly, only true if native touchable or web touchable device (client side, not server side).
useDidFinishSSR
SSR-friendly, returns true if SSR has completed on the client, false before hydration done. On server it’s always false.
Components
ClientOnly
A component that opts its children out of SSR. When wrapped in ClientOnly,
Tamagui avoids double-renders in various places which results in faster
client-side rendering.
Type helpers
GetProps
Fetches the type of props for a Tamagui component:
GetRef
Fetches the type of a ref for a Tamagui component, or any React component: