How to abort Meteor Methods

Hi, I am using react useEffect hook for calling meteor methods in my app, but it showing a react warning in my browser console

Warning: Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function

how can i fix this issue, is there a way to abort meteor RPC (Meteor methods) in callback function using AbortController()?

See this answer in SO.

1 Like

Thank you @peterfkruger will check this. :slight_smile:

I do this way so you don’t have to create a variable to check on every method call:

// check if the component is mounted
  const mounted = useRef(true);
  useEffect(
    () => () => {
      mounted.current = false;
    },
    [],
  );

// then in method callback
      Meteor.call('some.method', (error, result) => {
      if (mounted.current !== true) {
        // I don't want to update the unmounted component
        return;
      }
1 Like