Next.js Discord

Discord Forum

Failed to construct 'Image': Please use the 'new' operator

Answered
West African Crocodile posted this in #help-forum
Open in Discord
West African CrocodileOP
Hi guys, i am trying to make sort of gallery where onClick() on Image creates new Image of same src, but with diferent class, position etc.
This is my code:


and this is error I am getting:
Answered by joulev
try onClick={() => setZoomImage(false)} instead of onClick={setZoomImage(false)}
View full answer

29 Replies

you very likely used Image somewhere without importing next/image
West African CrocodileOP
i don't think so
these are my files
the files are fine. search for all the places in your project that you use Image
what is the search result?
West African CrocodileOP
ok one moment sorry
am kinda new with all this 😅
these are results
this is componentImage.jsx file
weird... it's looks fine to me. can you send me the link to the repo?
West African CrocodileOP
sure one moment
here
its private
West African CrocodileOP
here try now, sorry haven't been in programming for while so am bit slow with stuff
@West African Crocodile https://github.com/KrNovak97/demo
try onClick={() => setZoomImage(false)} instead of onClick={setZoomImage(false)}
Answer
West African CrocodileOP
working!
thank you so much
❤️
you're welcome
@joulev try `onClick={() => setZoomImage(false)}` instead of `onClick={setZoomImage(false)}`
West African CrocodileOP
btw you have any idea why it didn't work the way i did?
@West African Crocodile btw you have any idea why it didn't work the way i did?
onClick has to be a function, setZoomImage(false) is not a function
West African CrocodileOP
i see
thank you