0

I want to select data from query result

function useGetItemById(id: string) {
  return api.endpoints.getItemList(undefined, {
    selectFromResult: ({ data, ...rest }) => ({
      ...rest,
      data: data?.find(item => item.id === id)
    })
  });
}

...
// But the data type is T[] and not just T
const { data } = useGetItemById('1'); 

What should I do to get just T?

  • That should actually just work. Could you create a small reproduction and open an issue in the RTK repo? – phry Nov 29 '21 at 22:08
  • 1
    It was my mistake because I also used second argument `options?: any` and spread it in object. I mean `{ ...options, selectFromResult: () => ({ ... }) }` – ilya kirillov Dec 06 '21 at 19:57

0 Answers0