How to transform string values from Figma before passing them to `example`?

Open
#320 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
figma, typescript

Research direction

Start by reading the Code Connect documentation and the prop mapping behavior around figma.string and example; the issue provides a reproduction using an Errors component that expects a string array. Determine whether transforming mapped values is supported or needs a new API, then confirm the expected generated output for the reproduction. Done means the supported path is documented or the limitation and roadmap status are clarified.

Written by the indexing model from the issue text.

Description

API question

Is there a way to perform operations on the prop values coming from Figma, before they're passed to example?

My scenario is as follows:

  • We have an Errors component that accepts an array of error messages (as strings), ie. <Errors errors={['Error 1', 'Error 2']} />
  • The design component in Figma has a single text property, where the error messages are specified

Currently I have the following in my Code Connect file:

import figma from '@figma/code-connect';

import { Errors } from 'src/components';

figma.connect(
  Errors,
  '[redacted]',
  {
    props: {
      errors: figma.string('text'), // I'd like to transform this to an array, ie. `[figma.string('text')]`
    },
    example: ({ errors }) => <Errors errors={errors} />,
  },
);

Since the Errors component only accepts an array of strings, and not a single string, the above doesn't work. I need to be able to put figma.string('text') into an array, however nothing I tried seems to work.

If I do the following, then Figma renders it as-is, without using the actual value of errors:

example: ({ errors }) => <Errors errors={[errors]} />,

And if I try putting figma.string('text') into an array before passing it to example, then I get <Errors errors={[undefined]} /> output in Figma.

Is there a way to accomplish this? If not currently, is this something that is on the roadmap? Not being able to perform operations on the values coming from Figma is pretty limiting IMO.

Code Connect version: 1.3.5
OS: MacOS 26 (Tahoe)

Dominant language
TypeScript
Stars
1.6k
Forks
126
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from figma/code-connect

All issues in figma/code-connect

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.