question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to execute 'requestAnimationFrame' on 'Window' when storing zoom level in state

See original GitHub issue

I get this error when i use the onZoomChange to store the current zoom level in my components state. this is an extract of my code, if i comment out the setZoom() statement below it works fine again.

    ....
    const [zoom, setZoom] = useState<number>();
    const zoomChange = ({ scale }) => {
        console.log('zoom', scale);
        setZoom(scale);
    };

    return (
        <SelectionProvider>
            <TransformWrapper {...opts} onZoomChange={zoomChange}>
                {({ zoomIn, zoomOut, resetTransform }) => (
                    <>
                        <TransformComponent>
                            <div className="graphView__container">
                                <Graph
                                    graph={graph}
                                    bounds={graphBounds}
                                    zoom={zoom || 1}
                                />
                            </div>
                        </TransformComponent>
                        <ToolButtons
                            zoomIn={zoomIn}
                            zoomOut={zoomOut}
                            resetTransform={resetTransform}
                        />
                    </>
                )}
            </TransformWrapper>
    );
TypeError: Failed to execute 'requestAnimationFrame' on 'Window': The callback provided as parameter 1 is not a function.
animation
src/store/animations/index.ts:35
    32 |     this.animation = null;
    33 |   } else {
    34 |     callback(step);
  > 35 |     requestAnimationFrame(this.animation);
    36 | ^  }
    37 | };
    38 | 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

5reactions
frxzncommented, Jan 3, 2021

I needed to toggle between zoomIn/reset mode on doubleClick depending on the zoom state. I was getting the same error, so what I did is to wait for the animation to finish (which defaults to 200ms) before setting the state, using setTimeout

const [zoom, setZoom] = useState(false);

const handleZoom = (e) => {
    if (e.scale > 1 && !zoom) {
      setTimeout(() => {
        setZoom(true);
      }, 200);
    } else if (e.scale === 1 && zoom) {
      setZoom(false);
    }
  };

<TransformWrapper
    onZoomChange={handleZoom}
    doubleClick={{ mode: zoom ? 'reset' : 'zoomIn' }}
>
   ...
3reactions
pasierbcommented, Jun 16, 2020

facing same issue =( any quick workarounds?

@edwinlimlx a quick workaround that worked for me was to use function child (or whatever it’s called in react world)

<TransformWrapper
        defaultScale={1}
        options={{
          minScale: 0,
          centerContent: true,
          limitToBounds: false
        }}
      >
        {({ resetTransform, zoomIn, zoomOut, scale }) => (
           ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

The callback provided as parameter 1 is not a function. ...
Failed to execute 'requestAnimationFrame' on 'Window': The callback provided as parameter 1 is not a function.
Read more >
requestAnimationFrame and PAUSING Animation - YouTube
In NativeScript 6.5 a new function has been added that we've been waiting for - requestAnimationFrame. In this NativeScript tutorial, ...
Read more >
Leaflet 1.7 documentation
Returns the minimum zoom level of the map (if set in the minZoom option of the map or of any layers), or 0...
Read more >
JSDoc: Source: fabric.js
createHTMLDocument(''); } fabric.window = window; } else { // assume we're running under node.js when document/window are not present var jsdom ...
Read more >
NW.js Documentation
win.maximize(). Maximize the window on GTK and Windows, and zoom the window on Mac OS X. ... Restore window to previous state after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found