Skip to content

Is it possible to display existing records as tags using the useSelect(), #1651

Answered by omeraplak
BenGardiner123 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @BenGardiner123 ,
Thank you for contacting us! The easiest way to do this is to use the queryResult returned from the useSelect hook.

I created a CodeSandbox for you, https://codesandbox.io/s/refine-use-select-example-forked-s55ne?file=/src/pages/posts/create.tsx

const {
    selectProps,
    queryResult,
    defaultValueQueryResult
  } = useSelect();

  const allOptions = [
    ...(queryResult.data?.data || []),
    ...(defaultValueQueryResult.data?.data || [])
  ];

<Select
  {...categorySelectProps}
  options={allOptions.map((p) => ({
     label: `${p.title}-${p.id}`,
     value: p.id
   }))}
/>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by omeraplak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants