React 19 hooks library and CLI for the official Figma Variables REST API. Type-safe synchronization between Figma and React apps with 100% test coverage.
Test coverage with Vitest ensuring reliability for production use
Full TypeScript support with runtime guards and error helpers
MIT licensed and actively maintained for the design systems community
Design systems teams using Figma Variables faced a critical workflow challenge: there was no official way to programmatically access Figma's design variables from React applications. This created:
When Figma released their Variables REST API in 2024, I saw an opportunity to build the missing piece: a React hooks library that made Figma Variables a first-class citizen in React development.
FigmaVars Hooks is a React 19 hooks library that provides type-safe access to the Figma Variables REST API, paired with a CLI tool for exporting variables into CI/CD pipelines.
A lightweight provider wraps your app while hooks fetch and cache variables with SWR under the hood:
import { FigmaVarsProvider, useVariables } from '@figma-vars/hooks'
const FIGMA_TOKEN = process.env.NEXT_PUBLIC_FIGMA_TOKEN
const FIGMA_FILE_KEY = 'your-file-key'
export function App() {
return (
<FigmaVarsProvider token={FIGMA_TOKEN} fileKey={FIGMA_FILE_KEY}>
<Variables />
</FigmaVarsProvider>
)
}
function Variables() {
const { data, isLoading, error } = useVariables()
if (isLoading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
const variables = Object.values(data?.meta.variables ?? {})
return <pre>{JSON.stringify(variables, null, 2)}</pre>
}Built custom React hooks that fetch and cache Figma variables at runtime:
useFigmaVariables() - Fetch all variables from a Figma fileuseFigmaVariable() - Get a specific variable by ID or nameuseFigmaCollection() - Access variable collectionsCreated figma-vars-export CLI for exporting Figma variables as
JSON in CI/CD pipelines:
FIGMA_TOKEN=your_token npx figma-vars-export --file-key YOUR_FILE_KEY --out ./figma-variables.json
FIGMA_TOKEN=your_token figma-vars-export --file-key YOUR_FILE_KEY --out ./figma-variables.json
figma-vars-export --helpWrap stories once and surface live variables across your component docs:
// .storybook/preview.tsx
import { FigmaVarsProvider } from '@figma-vars/hooks'
import type { Preview } from '@storybook/react'
const FIGMA_TOKEN = process.env.STORYBOOK_FIGMA_TOKEN
const FIGMA_FILE_KEY = process.env.STORYBOOK_FIGMA_FILE_KEY
const preview: Preview = {
decorators: [
Story => (
<FigmaVarsProvider token={FIGMA_TOKEN} fileKey={FIGMA_FILE_KEY}>
<Story />
</FigmaVarsProvider>
),
],
}
export default previewTeams without Enterprise can still ship by exporting JSON once and using
fallbackFile for static or local environments. This keeps
Storybook and design system dashboards in sync without live API calls.
import exportedVariables from './figma-variables.json'
<FigmaVarsProvider
token={null}
fileKey={null}
fallbackFile={exportedVariables}
>
<App />
</FigmaVarsProvider>The library ships type guards and error helpers so apps can validate data and respond to API failures without guessing.
isLocalVariablesResponse() - Validate local responsesisPublishedVariablesResponse() - Validate published dataisFigmaApiError() + helpers for status code handlingredactToken() for safe logging and support flowsBuilt comprehensive test suite with Vitest covering:
Leveraged React 19's new capabilities:
A core build ships for non-React use cases (server scripts, TanStack Query, or custom fetchers) while preserving the same data contracts.
Token handling and rate-limit resilience are built in:
FigmaVars Hooks bridges the gap between Figma Variables and React development while keeping design systems predictable at scale:
Eliminates manual token sync by providing programmatic access to Figma Variables directly from React
Type-safe runtime validation ensures variables are valid before use in applications
100% test coverage provides confidence for teams adopting the library in production
Open-source contribution to the design systems community, filling a critical gap in the Figma Variables ecosystem
CLI tool enables CI/CD workflows that auto-sync design tokens on every Figma change
Enterprise and offline paths cover both live API usage and static exports for non-Enterprise teams
The library is published on npm, actively maintained, and is the backbone for teams building production token pipelines, Storybook dashboards, and Figma-to-code workflows.