Why state not updating from useMutation?

Why state not updating from useMutation?


0

I’m trying to update state(useState) from useMutation(Apollo Client) callbacks, but it is not updating the state. Setting it inside "error" callback.

Getting error in 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.

My component is hidden before updating those state. Not sure if that could be the reason. If yes, please provide some fix for it.

const [createNewList, { loading: createLoading, error: createError, data: createData }] = useMutation(
            CREATE_LIST,
            { 
                onCompleted(data) {
                    alert('created')
                }, 
                onError(error) {
                    props.displyModal();
                    setModalType('info');
                    setModalTitle('Error');
                    setModalMessage('error');
                } 
            }
        );


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *