Ask questionsuseEffect causes 'callback is not a function' exception

Do you want to request a feature or report a bug? Bug

What is the current behavior?

useEffect results in the following exception in the console:

Uncaught TypeError: callback is not a function
    at flushFirstCallback (scheduler.development.js:348)
    at flushWork (scheduler.development.js:441)
    at (scheduler.development.js:188)

I am unable to isolate the problem enough to create a sandbox that reproduces it. I am posting it here in case there is still some value in it (it seems slightly related to, and even This is my component:

const RemoteControlledSliderRaw = ({ activeIndex, currentlyDragging, className, children }) => {
	const [forcedX, setForcedX] = React.useState(null);

	React.useEffect(() => {
		if (currentlyDragging) {
			window._animateItem.update = setForcedX;
		} else {
			if (window._animateItem.update) {
				window._animateItem.update = null;
	}, [currentlyDragging]);

	return (
			<SliderCore activeIndex={activeIndex} forcedX={forcedX} className={className}>

What might be interesting is that I set a global object to point to a setState setter. That can be called from the outside. I am not sure exactly how the exception occurs, but if I comment out the entire useEffect bit, it goes away.

What is the expected behavior? No exception. Or at least one that provides some explanation as to what is wrong.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

16.8.6. I don't know if this worked with earlier versions.


Answer questions Shrroy

Same problem: using setInterval just doesn’t work as I'd expect with react-native

const [time, setTime] = useState(0);
        useInterval(() => {
            setTime(time +1);

        return (<Text>{time}</Text>);

function useInterval(callback) {
    const savedCallback = useRef();

    // Remember the latest function.
    useEffect(() => {
        savedCallback.current = callback;
    }, [callback]);

    // Set up the interval.
    useEffect(() => {
            let id = setInterval(()=>savedCallback.current(), delay);
            return () => clearInterval(id);

I'm getting an error says "Callback() it's not a function"

enter image description here

It's working as expected in Reactjs

"dependencies": {
    "react": "16.8.3",
    "react-native": "^0.59.6",
Github User Rank List