image-map-resizer icon indicating copy to clipboard operation
image-map-resizer copied to clipboard

React

Open antonydellavecchia opened this issue 5 years ago • 9 comments

Has anyone been able to get this working with react? I am just migrate my project to react now and having some trouble getting this to work.

antonydellavecchia avatar Sep 14 '18 14:09 antonydellavecchia

I don’t think this will work in React in it’s current form, but now you have me thinking what a React version would look like. I will give it some thought over the weekend

davidjbradshaw avatar Sep 15 '18 08:09 davidjbradshaw

got it to work, just render the html area map like you normally would, import imageMapResize from 'image-map-resizer' and call imageMapResize inside componentDidMount() makes sense aha,

antonydellavecchia avatar Sep 26 '18 14:09 antonydellavecchia

I have done the as @antonydellavecchia but I am getting an error ReferenceError: window is not defined at /something/node_modules/image-map-resizer/js/imageMapResizer.min.js:7:1833

mritunjayupadhyay avatar Feb 04 '19 09:02 mritunjayupadhyay

One additional thing I had to do (in addition to what @antonydellavecchia said is add the following eslint rule:

/* eslint no-undef: "off"*/ 

jdejesus001 avatar Jun 13 '19 17:06 jdejesus001

Hi @jdejesus001 , Where should I add that rule? I'm also facing the same error as miritun when refresh page. I'm using nextjs, typescript.

iACM1994 avatar Jul 03 '19 08:07 iACM1994

Would be easier to set the esLint environment to browser

{
  "env": {
    "browser": true
  }
}

davidjbradshaw avatar Nov 13 '19 14:11 davidjbradshaw

I added the rule on line 147 of the ImageMapResizer file:

 /* eslint no-undef: "off"*/
  if (typeof define === 'function' && define.amd) {
    define([], factory)
  } else if (typeof module === 'object' && typeof module.exports === 'object') {
    module.exports = factory() //Node for browserfy
  } else {
    window.imageMapResize = factory()
  }

jdejesus001 avatar Nov 13 '19 15:11 jdejesus001

Nice job btw David. I have this working perfectly in React.

jdejesus001 avatar Nov 13 '19 15:11 jdejesus001

for those doing it in nextjs, this worked for me:

useEffect(() => {
    import("image-map-resizer").then((module) => module.default());
  }, []);

panzerstadt avatar Jul 08 '21 16:07 panzerstadt