Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook does not cause re-render when setContainer() is called. #26

Open
ChrisLincoln opened this issue Jul 2, 2021 · 0 comments
Open

Comments

@ChrisLincoln
Copy link

Thank you for the very handy hook. I have a container-dependent useEffect where I do some calculations based on the transform and the dimensions of the interactive container.

const {
    transform,
    panZoomHandlers,
    setContainer,
    setPan,
    setZoom,
    pan,
    zoom,
    container
  } = usePanZoom();


  useEffect(() => {
    // Do other stuff based on container dimensions & pan/zoom
    // This useEffect won't fire until the user pans/zooms.
    console.log(container ? "Container is valid" : "container is not set");
  }, [pan, zoom, container]);

I worked around it by setting zoom to 1 upon initial render:

  useEffect(() => {
    setZoom(1);
  }, [setZoom]);

See the codesandbox fork for the full example.

https://codesandbox.io/s/use-pan-zoom-example-forked-eg4el?file=/src/app.tsx

I wouldn't necessarily call this a bug, but I would appreciate a pointer in the right direction if there is a better workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant