next.js useState problem.
Unanswered
Asian swamp eel posted this in #help-forum
Asian swamp eelOP
Not able to use useState in next.js
Hey everyone I am kind of beginner to next.js.
My concern is I was watching a tutorial and they were using useState and their code was working properly I copied the code but mine is not working.
I even found this question on Google but I didn't get the answer.
Code of page.js
||||||||||
"use client"
import React, { useState } from 'react'
const Page = () => {
const [marks, setMarks] = useState(80)
return (
#Unknown Channel
<h1>My marks were {marks}</h1> <button onClick={() =>{setMarks(33)}}>Update</button>
</>
}
export default Page
||||||||||||||
When I click on to update button nothing changes.
Please guide me.
Hey everyone I am kind of beginner to next.js.
My concern is I was watching a tutorial and they were using useState and their code was working properly I copied the code but mine is not working.
I even found this question on Google but I didn't get the answer.
Code of page.js
||||||||||
"use client"
import React, { useState } from 'react'
const Page = () => {
const [marks, setMarks] = useState(80)
return (
#Unknown Channel
<h1>My marks were {marks}</h1> <button onClick={() =>{setMarks(33)}}>Update</button>
</>
}
export default Page
||||||||||||||
When I click on to update button nothing changes.
Please guide me.
1 Reply
@Asian swamp eel Not able to use useState in next.js
Hey everyone I am kind of beginner to next.js.
My concern is I was watching a tutorial and they were using useState and their code was working properly I copied the code but mine is not working.
I even found this question on Google but I didn't get the answer.
Code of page.js
||||||||||||||||||||||||||||||||||||||||||||||
"use client"
import React, { useState } from 'react'
const Page = () => {
const [marks, setMarks] = useState(80)
return (
<>
<h1>My marks were {marks}</h1> <button onClick={() =>{setMarks(33)}}>Update</button>
</>
}
export default Page
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When I click on to update button nothing changes.
Please guide me.
The tutorial you're watchintg is showcasing older way of working with nextjs(pages dir). The new way(app dir) to work with nextjs is slight different. There are no up to date tutorials that ik. The only way to learn the newer version is to read the [Docs](https://nextjs.org/docs)