TanStackT
TanStack2y ago
29 replies
primary-violet

Handling rerendering and useMutation

Hi all, currently when wanting to force a rerender on a mutation I move the mutation up in state and pass it as a callback down to the component that needs to trigger it. This often results in prop drilling and coupled state. What is a better approach?

Simplified example:
const Chat = () => {
  const { mutate: addMessage } = useAddMessage();

  return(
   <ChatHeader>
   <ChatMessages>
   <ChatInput addMessage={addMessage}>
  );
}


The useAddMessage hook inserts the message into the cache of an InfiniteQuery using
setQueryData


Using version 4.24.6
Was this page helpful?