Skip to content

Minor RTK mutation function call fix #4577

Description

@weixin-tan

What docs page needs to be fixed?

  • Section: Redux Essentials
  • Page: Part 8 RTK Query Advanced Patterns

What is the problem?

Seems like a minor typo/missing function call in the usage of mutation function. In part 7, it is stated that the .unwrap() function needs to be called for the RTK mutation query.

As with the thunk dispatch, we call addNewPost with the initial post object. This returns a special Promise with a .unwrap() method, and we can await addNewPost().unwrap() to handle any potential errors with a standard try/catch block.

Whereas in part 8 code snippet for Editing Post, the .unwrap() call is missing for a very similar mutation function.

  const [updatePost, { isLoading }] = useEditPostMutation()

  /* code omitted */

  const onSavePostClicked = async () => {
    if (title && content) {
      await updatePost({ id: postId, title, content }) // <- this should have a .unwrap() ?
      history.push(`/posts/${postId}`)
    }
  }

What should be changed to fix the problem?

Add .unwrap() to the code snippet

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions