Skip to content

Commit

Permalink
next.js onLoad problem fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
NishargShah committed Mar 5, 2022
1 parent 0e8d54e commit e2240fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-img-mapper",
"version": "1.3.0",
"version": "1.4.0",
"description": "React Component to highlight interactive zones in images",
"keywords": [
"react",
Expand Down
14 changes: 7 additions & 7 deletions src/ImageMapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const ImageMapper: React.FC<ImageMapperProps> = (props: ImageMapperProps) => {
const ctx = useRef<CanvasRenderingContext2D>(null);
const isInitialMount = useRef<boolean>(true);

useEffect(() => {
initCanvas(true);
ctx.current = canvas.current.getContext('2d');
updateCacheMap();
setRendered(true);
}, []);

useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
Expand All @@ -62,12 +69,6 @@ const ImageMapper: React.FC<ImageMapperProps> = (props: ImageMapperProps) => {
}
}, [props, isInitialMount, imgRef]);

useEffect(() => {
ctx.current = canvas.current.getContext('2d');
updateCacheMap();
setRendered(true);
}, []);

useEffect(() => {
container.current.clearHighlightedArea = () => {
setMap(storedMap);
Expand Down Expand Up @@ -293,7 +294,6 @@ const ImageMapper: React.FC<ImageMapperProps> = (props: ImageMapperProps) => {
useMap={`#${map.name}`}
alt="map"
ref={img}
onLoad={() => initCanvas(true)}
onClick={event => imageClick(event, props)}
onMouseMove={event => imageMouseMove(event, props)}
/>
Expand Down

0 comments on commit e2240fa

Please sign in to comment.