Git Product home page Git Product logo

Comments (6)

azatris avatar azatris commented on July 29, 2024 2

Same goes for vue.js.

from drift.

wiesson avatar wiesson commented on July 29, 2024 2

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

from drift.

a-tonchev avatar a-tonchev commented on July 29, 2024 1

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>
);

from drift.

sherwinski avatar sherwinski commented on July 29, 2024

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

from drift.

ChetSocio avatar ChetSocio commented on July 29, 2024

Can you guys write it for typescript react 18?

from drift.

mattlaguardia avatar mattlaguardia commented on July 29, 2024

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.

from drift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.