Skip to content

Combobox: Accepting object as well as value in ComboboxItem #3508

Answered by diegohaz
PixeledCode asked this question in Questions
Discussion options

You must be logged in to vote

Instead of JSON.stringify, you can maintain a separate array with your objects (which you probably already have) and retrieve the object for the value on setSelectedValue:

const options = [
  { value: "a", label: "A" },
  { value: "b", label: "B" },
  { value: "c", label: "C" },
];

function getOptionFromValue(value: string) {
  return options.find((option) => option.value === value);
}

<ComboboxProvider
  setSelectedValue={(value) => {
    const option = getOptionFromValue(value);
    ...
  }}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PixeledCode
Comment options

Answer selected by PixeledCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants