1

Hope you all are doing fine.

RTK queries return response in data attribute which can be accessed via hook generated by RTK

My Code:

const {data = [], isFetching} = useFetchConversationQuery(categoryId, {
    skip
});
const { data } = useFetchCategoryQuery();

My issue is that I'm trying to call 2 RTK queries in a react component so there cant be two attribute with the same name is there a way to change the name of data attribute in RTK queries,

phry
  • 35,762
  • 5
  • 67
  • 81
Obaid Aqeel
  • 199
  • 1
  • 1
  • 10

2 Answers2

1

I believe there's no way to change the RTK data attribute name, however what you can instead do is simply assign a different name when you destructure your object.

const {data = [], isFetching} = useFetchConversationQuery(categoryId, {
    skip
});
const { data: myNewDataName } = useFetchCategoryQuery();

myNewDataName // data from useFetchCategoryQuery
Secret
  • 3,291
  • 3
  • 32
  • 50
0

I also have realized this limitation. This is not exactly what you are looking for but you can use them like this;

const conversation = useFetchConversationQuery(categoryId, {
    skip
});
const category = useFetchCategoryQuery();

// conversation.data.map(item=>console.log(item._id));
// console.log(category.data)
yalcinozer
  • 305
  • 1
  • 3
  • 9