Simple client side component doesn't seem to work
Answered
Savannah posted this in #help-forum
SavannahOP
I can't get the simplest client side component to work in my brand new NextJs project. I have a very simple project structure:
I am able to see the text and button and click on it...but
└───app
│ favicon.ico
│ globals.css
│ layout.tsx
│ page.module.css
│ page.tsx
│
└───components
counter.tsx// page.tsx
import Counter from "@/app/components/counter";
export default function Home() {
return (
<Counter/>
)
}// components/counter.tsx
'use client'
import { useState } from 'react'
export default function Counter() {
const [count, setCount] = useState(0)
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
)
}I am able to see the text and button and click on it...but
count doesn't change, no errors in either the browser console or the terminal. Pretty sure I am being very dumb, but I am so confused haha. Any help is appreciated!Answered by Savannah
...Checked my node version and saw I was on 16, updated to 18 and now it works as expected. Knew it would be something dumb, this is solved 😄
1 Reply
SavannahOP
...Checked my node version and saw I was on 16, updated to 18 and now it works as expected. Knew it would be something dumb, this is solved 😄
Answer