Use selectFromResult with normalized data
See original GitHub issueI suspect the answer is “no”, but I would like your confirmation: it does make sense to use selectFromResult with normalized data?
Like:
export const commentaryAdapter = createEntityAdapter({
// Assume IDs are stored in a field other than `book.id`
selectId: commentary => commentary.attributes.id,
});
const { selectAll: selectAllCommentaries, selectById: selectCommentaryById } =
commentaryAdapter.getSelectors(state => {
return selectCommentaryEvents(state);
});
const commentaries = useSelector(state => selectAllCommentaries(state));
const { commentaryEvents } =
useGetMatchResultQuery(
{
matchId: matchId,
},
{
selectFromResult: result => {
return {
...result,
commentaryEvents: commentaries,
};
},
},
);
Or, if you use normalized data, selectFromResult
doesn’t make sense?
Issue Analytics
- State:
- Created a year ago
- Comments:9
Top Results From Across the Web
Redux Essentials, Part 8: RTK Query Advanced Patterns
The official Redux Essentials tutorial: learn advanced patterns for fetching data with RTK Query.
Read more >ReduxToolKit: correct way to use SelectFromResult options in ...
If I comment out the SelectFromResult option they are then correctly returned. export const PokemonList = () => { const { data, error,...
Read more >Connecting RTK Query API with redux reducer and selector ...
[Solved]-Connecting RTK Query API with redux reducer and selector-Reactjs ... You missed an important bit: RTK-Query is not a normalized cache, but a...
Read more >Redux Toolkit 1.6.0 - new RTK Query data caching API! - Reddit
RTK Query is a powerful and easy-to-use server data caching solution ... RTK Query is not a normalized store and you do not...
Read more >Normalized Caching | urql Documentation
For our apps normalized caches can enable more sophisticated use-cases, where different API requests update data in other parts of the app and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, so what I was saying applies here.
If you do nothing, by default
const { data } = useMyQuery()
will give you back the entire{ids: [], entities: {}
structure you returned fromtransformResponse
.If you only want part of that, like a single item by its ID, then you should use
selectFromResult
to pick out just that one piece.You’d want to use the entity adapter selectors. Specifically, you’d need to use the “localized” versions, generated by calling
myAdapter.getSelectors()
without an input selector:https://redux-toolkit.js.org/api/createEntityAdapter#selector-functions
And then
const allItemsAsArray = selectors.selectAll(res.data)
intransformResponse
.