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

Drift for react js. #380

Closed
devaman opened this issue Dec 4, 2019 · 6 comments
Closed

Drift for react js. #380

devaman opened this issue Dec 4, 2019 · 6 comments

Comments

@devaman
Copy link

devaman commented Dec 4, 2019

It would be really great if drift can be used in reactjs apps, simply out of box. Right now integrating it with react js is little bit complex.

@azatris
Copy link

azatris commented May 22, 2020

Same goes for vue.js.

@wiesson
Copy link

wiesson commented Oct 15, 2020

Regarding react:

const imgRef = React.useRef();
const paneRef = React.useRef();

React.useEffect(() => {
  // lazy loading, you also import is as regular
  let Drift;
  if (typeof window !== "undefined") {
    Drift = require("drift-zoom").default;
  }
  new Drift(imgRef.current, { paneContainer: paneRef.current });
}, []);

return (
  <div>
    <img ref={imgRef} src="..." data-zoom="..." />
    <div ref={paneRef} />
  </div>
);

Working example https://codesandbox.io/s/drift-zoom-preact-c25ff

@a-tonchev
Copy link

Don't forget to use destroy when unmounting component.

I would recommend to place Drift outside the component, so that you don't reload the library every time you open the component.

const imgRef = React.useRef();
const paneRef = React.useRef();
let Drift;

React.useEffect(() => {
  // lazy loading, you also import is as regular
  if (!Drift && typeof window !== "undefined") {
    Drift = require("drift-zoom").default;
  }
  let driftElement = new Drift(imgRef.current, { paneContainer: paneRef.current });
  
  return () => {
    driftElement.destroy();
  }
}, []);

return (
  <div>
    <img ref={imgRef} src="..." data-zoom="..." />
    <div ref={paneRef} />
  </div>
);

@sherwinski
Copy link
Contributor

Closing as there hasn't been much activity on here lately and it looks like several answers have been provided.

@ChetSocio
Copy link

Can you guys write it for typescript react 18?

@mattlaguardia
Copy link
Contributor

Hi @ChetSocio, unfortunately we are no longer maintaining this project I would recommend using something like: https://github.com/ethanselzer/react-image-magnify or if you're interested in taking over the project we are looking for a maintainer see: #703.

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

7 participants