{ml}
Back to work
DEVELOPER TOOLS

FigmaVars Hooks

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.

Role
Creator & Maintainer
Timeline
2024 - Present
Technologies
React 19TypeScriptFigma REST APIVitestNode.jsCLInpm

Impact

100%

Test coverage with Vitest ensuring reliability for production use

Type-Safe

Full TypeScript support with Zod validation for runtime safety

Open Source

MIT licensed and actively maintained for the design systems community

The Problem

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:

  • Manual copy-paste workflows to sync design tokens from Figma to code
  • Version drift between Figma variables and application code
  • No way to validate variables at runtime in React apps
  • Inability to dynamically load Figma variables in Storybook or dev tools
  • Fragmented token export solutions that didn't leverage official APIs

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.

The Solution

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.

React Hooks API

Built custom React hooks that fetch and cache Figma variables at runtime:

  • useFigmaVariables() - Fetch all variables from a Figma file
  • useFigmaVariable() - Get a specific variable by ID or name
  • useFigmaCollection() - Access variable collections
  • Built-in caching and request deduplication for performance
  • Full TypeScript support with inferred types from Zod schemas

CLI Export Tool

Created figma-vars-export CLI for exporting Figma variables as JSON in CI/CD pipelines:

  • Runs in GitHub Actions or any CI environment
  • Exports variables to JSON format compatible with Style Dictionary
  • Supports filtering by collection, mode, or variable name
  • Validates exported data against Zod schemas before writing

Zod Validation

All API responses are validated at runtime using Zod schemas, ensuring type safety beyond TypeScript's compile-time checks. This prevents runtime errors from malformed API data and provides clear error messages when validation fails.

100% Test Coverage

Built comprehensive test suite with Vitest covering:

  • All hook behaviors and edge cases
  • API request/response mocking and error handling
  • Zod schema validation for all data structures
  • CLI command execution and file output

Technical Architecture

React 19 Features

Leveraged React 19's new capabilities:

  • Server Components for initial data fetching when used in Next.js
  • Use hook for async data loading
  • Built-in caching strategies with React's cache function

Developer Experience

Optimized for DX:

  • Clear error messages with suggestions for common issues
  • Comprehensive TypeScript types exported from package
  • Detailed README with code examples and API reference
  • Minimal configuration required to get started

Use Cases

Enables powerful workflows:

  • Live Storybook integration showing actual Figma variables
  • Design token validation tools that check Figma against codebase
  • Admin panels for managing design tokens across teams
  • CI/CD pipelines that auto-sync Figma changes to code repos

Impact & Adoption

FigmaVars Hooks bridges the gap between Figma Variables and React development:

  • Eliminates manual token sync by providing programmatic access to Figma Variables directly from React
  • Type-safe runtime validation using Zod 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

The library is published on npm, actively maintained, and serves as a foundation for teams building design token workflows with Figma Variables.

© 2026 Mark Learst.Crafted with precision
v2026.1.0