Next.js Discord

Discord Forum

Client components not being interactive

Answered
Ojos Azules posted this in #help-forum
Open in Discord
Avatar
Ojos AzulesOP
I have an extremely simple component as my root page:

"use client";

export default function Page() {

    return (
        <main className={"flex min-h-screen flex-col items-center p-24 gap-12"} onClick={() => console.log("Hello World!")}>
            <h1 className={"text-xl"}>Hello!</h1>
        </main>
    )
}


The main Element obviously takes up the entire page, which can be seen in the dev tools. The onClick is never triggering. I also tried adding inputs with onChange listeners and everything, and the events never trigger.

I have tried adding useStates, console.logs, restarting the application multiple times but I can't get it to work. What am I doing wrong?

14 Replies

Avatar
Ojos AzulesOP
Even useEffects don't work, this doesn't print anything:
useEffect(() => {
  console.log("USE EFFECT")
}, [])
Avatar
Ojos AzulesOP
It feels like the component just isn't being rendered on the client at all, since no console.logs or anything work on the client, while they do appear in the server console
Avatar
Hi,

I did a repro from what I understand of your issue here :
https://codesandbox.io/p/sandbox/client-component-effect-and-click-vt7f5w?file=%2Fapp%2Fpage.tsx%3A18%2C1

It is working fine from my side, can you explain a bit more about what is not working from your side?
Avatar
Ojos AzulesOP
Hey, thanks for you reply! This example is working inside of code sandbox for me, but on my machine it does not work.

I also tried simply running npx create-next-app test and then added click listeners to the default page, and made it a client component, that did not work either.

Could this have to do with my npm or node installation?
Avatar
🤔
What is your OS ? Node version ? And npm version ?
You might want to create a new issue on github for this
Avatar
Ojos AzulesOP
Windows 11, NPM 8.13.2, Node 16.10.0
Avatar
Can you try with the current node LTS ?
Answer
Avatar
System requirement seems to be 16.14 and more
Avatar
Ojos AzulesOP
Ah yeah that was it, latest node LTS works... thank you :D
I must say though, it would be helpful if next.js told you that your node version is too old
Avatar
Yeah, I do agree that would help! Glad we found out 🙂