1. 11
    Transform Cached RTK Query Data before Rendering with useMemo
    1m 23s

Transform Cached RTK Query Data before Rendering with useMemo

Share this video with your friends

Send Tweet

In this lesson we rely on useMemo to to give additional properties to data returned from our query hook. This is not the recommended approach to modifying a server response. That would be the transformResponse property shown in the next lesson, but I wanted to demonstrate how easy it was to combine typical react features like useMemo with RTK Query results. This approach can work well if you need to modify data in a single component and no where else. It can also be combined with a custom hook that encapsulates both the query and the useMemo call to be made more reusable. In the sample code I've provided an example of what that hook might look like.