T
TanStack3y ago
other-emerald

Should you use `select` to "transform" data?

I am making a query for an autosuggest and I want to change its shape. Would using select be a bad choice?
useQuery({
queryKey: ["games"],
queryFn: getAllGames,
select(games) {
return games.map(({ id, title, description }) => ({
value: id,
label: title,
description,
}));
}
});
useQuery({
queryKey: ["games"],
queryFn: getAllGames,
select(games) {
return games.map(({ id, title, description }) => ({
value: id,
label: title,
description,
}));
}
});
1 Reply
deep-jade
deep-jade3y ago
Not a bad choice, but "depends" is the answer. Pros and cons here: https://tkdodo.eu/blog/react-query-data-transformations
React Query Data Transformations
Learn the possibilities to perform the quite common and important task of transforming your data with react-query

Did you find this page helpful?