Next.js Discord

Discord Forum

how to make the components with onClick function from JSON file saved in project folder

Unanswered
German Pinscher posted this in #help-forum
Open in Discord
German PinscherOP
I'm working on creating a vocabulary test where users can click on the correct meaning of a word displayed at the top, similar to the image provided. The test content is generated from a JSON file saved in the project folder. However, I encountered an error when I tried to add the onClick function to each meaning card, resulting in the following message:

⨯ Error: Event handlers cannot be passed to Client Component
<... text=... onClick={function}>
^^^^^^^^^^
If you need interactivity, consider converting part of thi
at stringify (<anonymous>)
digest: "1544885474"

It appears that the fs.readFile() function can only run on the server side, while the onClick function needs to run on the client side I thought. To address this issue, I realize the need to separate the functions responsible for creating the contents and handling user interaction. Could you please guide me on how to achieve this?

0 Replies