I have created a new NextJS project with the latest version of Next (Next.js v13.4.19). I want to register onMouseEnter events for my application. A basic example works in this code sandbox: https://codesandbox.io/s/romantic-saha-9mvvwy?file=/index.js.
I use a simple sudo yarn create next-app --typescript
and then paste the Box code on the home page. My page.tsx looks like so:
import { Box } from "@material-ui/core";
import Image from "next/image";
export default function Home() {
return (
<Box
color="primary"
onMouseOver={(e) => console.log("onMouseEnter (first button)")}
onMouseOut={(e) => console.log("onMouseLeave (first button)")}
>
Hello World Edit
</Box>
);
}
I get an error about needing to specify if this is a client or server component, so I add the "use client" modifier at the top:
'use client'
import { Box } from "@material-ui/core";
import Image from "next/image";
export default function Home() {
return (
<Box
color="primary"
onMouseOver={(e) => console.log("onMouseEnter (first button)")}
onMouseOut={(e) => console.log("onMouseLeave (first button)")}
>
Hello World Edit
</Box>
);
}
There are no errors, but the events are not getting registered. Any suggestions?
2
Answers
I was able to solve it by downgrading my version of next from 13.4 to 13.0.6 in package.json
You need to use
createRoot
to render your app.Code sandbox – https://codesandbox.io/s/strange-sky-2cskff