Skip to content

RTK Query createApi Help: Any way to merge previous end point state with new response #2270

Closed
@kohding

Description

@kohding

I'm trying to find a way to not overwrite the previous responses state, but instead merge it with the new response for the same end point. This would prevent unnecessary load on the server since the data has already been requested on the first request. I also don't see a way to getState before the second request completes. Thanks in advance.

Example
First response.
{ text: 'This is the first response' }

Second response overwrites first response.
{ text2: 'This is the second response' }

What I would like with second response. Take the first response and merge it with the second response using the spread operator or if there is built-in functionality with RTK Query.
{ text: 'This is first response', text2: 'This is the second response' }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions