setInterval does not apply state changes until timeout ends

I’m trying to fetch data from a service and when any of states below changed, i want to clear the interval and keep going with new states

Tried this code but it didnt help.

 useEffect(() => {
        if(autoRefresh) {
            let intervalCall = setInterval(getTaskElements,6000);
            return () => {
                // clean up
                clearInterval(intervalCall);
            };
        }
    }, [changes, paging, taskParams, sorting, language,autoRefresh]);