0

I'm trying to figure out how to make a chakra-react-select form, with options for selection that are defined as an enum in the Prisma schema as follows:

enum Category {
  FUTURE
  NATURAL 
  SOCIAL
}

I can see the form in the docs looks as follows:

<Select
  isMulti
  options={[
    {
      label: "I am red",
      value: "I-am-red",
      
    },
    {
      label: "I fallback to purple",
      value: "i-am-purple",
    }
  ]}
  placeholder="Select categories"
  closeMenuOnSelect={true}
  onChange={onChange}
  onBlur={onBlur}
  value={value}
  ref={ref}
/>

I can't find an example of how to make the prisma enum Category, the select options. I don't care if both label and value are the categories.

How can I use enum values as the select options?

Joundill
  • 6,828
  • 12
  • 36
  • 50
Mel
  • 2,481
  • 26
  • 113
  • 273
  • There is a similar StackOverflow [post](https://stackoverflow.com/questions/68579505/how-to-get-enums-in-prisma-client). Does it address your question? – Raphael Etim Nov 22 '22 at 10:42

1 Answers1

0

You should be able to do something like this inside your select:

<Select
  placeholder="Select categories"
>
  {Object.keys(Category).map(cat => (<option>cat</option>))}
</Select>
Joundill
  • 6,828
  • 12
  • 36
  • 50