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
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>
}useFigmaVariables() - Fetch all variables from a Figma fileuseFigmaVariable() - Get a specific variable by ID or nameuseFigmaCollection() - Access variable collectionsfigma-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 --help// .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 previewfallbackFile 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>isLocalVariablesResponse() - Validate local responsesisPublishedVariablesResponse() - Validate published dataisFigmaApiError() + helpers for status code handlingredactToken() for safe logging and support flows