skip to Main Content

First time using NextJS, why is this not working. When clicking the button there is no log message in the browser. I have also tried adding onChange to an <input /> however again, doesn’t fire.

I have removed all styling from the globals.css and page.module.css file – this is literally a completely fresh NextJS project using npx create-next-app@latest

"use client";

export default function Home() {
  function handleClick() {
    console.log("hello");
  }

  return (
    <main>
      <button type="button" onClick={handleClick}>
        Click
      </button>
    </main>
  );
}

2

Answers


  1. Chosen as BEST ANSWER

    This was caused due to my Node.js being on v16.13.1. Updating to the latest version (currently v18.17.1) and also running npm update npm -g fixed the problem.


  2. There seems to be nothing wrong with the code. Please try to quit your node server and start again

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search