Skip to content

Stop suggesting using unwrap to have inline result #3515

Closed

Description

Imo these 2 statements are wrong and encourage developers using old-style Promise syntax instead async/await.

If you need to access the error or success payload immediately after a mutation, you can chain .unwrap().
https://redux-toolkit.js.org/rtk-query/usage/error-handling#error-display-examples

This can be useful if you wish to determine whether the mutation succeeds/fails inline at the call-site.
https://redux-toolkit.js.org/rtk-query/usage/mutations#frequently-used-mutation-hook-return-values

If i need to access payload immediately after a mutation I will use

const [trigger] = useMutation();
...
...
const result = await trigger(...);
// result is "the error or success payload retrieved immediately after a mutation" and can be used "to determine whether the mutation succeeds/fails inline at the call-site"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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