Skip to content

Commit e2240fa

Browse files
committed
next.js onLoad problem fixed
1 parent 0e8d54e commit e2240fa

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-img-mapper",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "React Component to highlight interactive zones in images",
55
"keywords": [
66
"react",

src/ImageMapper.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ const ImageMapper: React.FC<ImageMapperProps> = (props: ImageMapperProps) => {
5252
const ctx = useRef<CanvasRenderingContext2D>(null);
5353
const isInitialMount = useRef<boolean>(true);
5454

55+
useEffect(() => {
56+
initCanvas(true);
57+
ctx.current = canvas.current.getContext('2d');
58+
updateCacheMap();
59+
setRendered(true);
60+
}, []);
61+
5562
useEffect(() => {
5663
if (isInitialMount.current) {
5764
isInitialMount.current = false;
@@ -62,12 +69,6 @@ const ImageMapper: React.FC<ImageMapperProps> = (props: ImageMapperProps) => {
6269
}
6370
}, [props, isInitialMount, imgRef]);
6471

65-
useEffect(() => {
66-
ctx.current = canvas.current.getContext('2d');
67-
updateCacheMap();
68-
setRendered(true);
69-
}, []);
70-
7172
useEffect(() => {
7273
container.current.clearHighlightedArea = () => {
7374
setMap(storedMap);
@@ -293,7 +294,6 @@ const ImageMapper: React.FC<ImageMapperProps> = (props: ImageMapperProps) => {
293294
useMap={`#${map.name}`}
294295
alt="map"
295296
ref={img}
296-
onLoad={() => initCanvas(true)}
297297
onClick={event => imageClick(event, props)}
298298
onMouseMove={event => imageMouseMove(event, props)}
299299
/>

0 commit comments

Comments
 (0)