Skip to content
Discussion options

You must be logged in to vote

The problem is that you will only get the reset method for the currently running request in the next render.

createPost().then(() => reset());

reset here is a reference to the reset function that existed before createPost was started.

You could for example work around it like this:

  const [createPost, { reset }] = useCreatePostMutation();

  const resetRef = useRef(reset)
  resetRef.current = reset

  const handleClick = () => {
    createPost().then(() => resetRef.current());
  };

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@prajotKeywordio
Comment options

@shreyashByteridge
Comment options

Answer selected by prajotKeywordio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants