Im currently trying to setup a ternary operator condition in my onClick event in Next.js. But im getting an error saying my condition is returning nothing. Please help...
-
1DO NOT post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. For more information please see the Meta FAQ entry Why not upload images of code/errors when asking a question? Please edit your question to include the text.VLAZ– VLAZ2022-10-24 18:38:38 +00:00Commented Oct 24, 2022 at 18:38
Add a comment
|
2 Answers
You correctly included the addToCart as a function by not calling it.
The problem is that you did not do the same for alert. Your alert is called while rendering, so you are trying to set the onClick function to the return of the alert call.
Replace alert("aaaaa") with () => alert("aaaaaa") to wrap it in a function

