Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor RTK Mutation Query Function Documentation Fix #4578

Closed
wants to merge 1 commit into from

Conversation

weixin-tan
Copy link

Fix mutation function usage, according to part 7 an .unwrap() call is needed.


name: 📝 Documentation Fix
about: Fixing a problem in an existing docs page

Checklist

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 changes does this PR make to fix the problem?

Add .unwrap() to the code snippet

Fix mutation function usage, according to part 7 an `.unwrap()` call is needed.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 2, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b66769d:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration

@netlify
Copy link

netlify bot commented Jul 2, 2023

Deploy Preview for redux-docs ready!

Name Link
🔨 Latest commit b66769d
🔍 Latest deploy log https://app.netlify.com/sites/redux-docs/deploys/64a1437b7e5b14000808d1f5
😎 Deploy Preview https://deploy-preview-4578--redux-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@weixin-tan weixin-tan changed the title Update part-8-rtk-query-advanced.md Minor RTK Mutation Query Function Doucmentation Fix Jul 2, 2023
@weixin-tan weixin-tan changed the title Minor RTK Mutation Query Function Doucmentation Fix Minor RTK Mutation Query Function Documentation Fix Jul 2, 2023
@markerikson
Copy link
Contributor

Strictly speaking, the .unwrap() isn't needed here. Dispatching the mutation trigger will return a promise either way - it's just that it always resolves. .unwrap() is only needed if you want to convert that back into a potential thrown error:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants