skip to Main Content

I’m learning NEXT and there are functions that don’t work

"use client"

import { useState } from 'react'
export default function idk() {
    const [counter,setCounter]=useState(0)
    const add=()=>{
        setCounter(prev=>prev+1)
    }
    return(
            <div onClick={add}>
               {counter}
            </div>
    )
}

When the code is run, it creates the initial state of the counter but there is no change after that

I thought the problem was in the Hooks, but even the console doesn’t work

"use client"

export default function idk() {
    const ttc=()=>{ 
       console.log("i try to console")
    }
    return(
            <button onClick={ttc}> CLICK me </button >
    )
}

routing The page does not redirect directly, but rather reloads as if I were using several html pages

<Link href="/about"> about </Link>

This problem has been occurring since the first use of next

I do not think that the problem is in the code, but rather in my version, and there are notes that may help you understand my problem :

The same code works in react.js

When I create an application, I choose src in the settings

Sometimes the page becomes white and does not show the problem

Node version: v17.1.0

npm version:8.1.2

next version: @latest

I don’t know, but I tried to create the project again and some problems that I did not mention went away

2

Answers


  1. Chosen as BEST ANSWER

    @wantToBeAProgrammer Thanks you really solved all the problems

    To anyone who has the same problem, changing the version to a more stable version may solve your problems

    If you want to know how to change the version of the next:

    1. delete node_modules folder
    2. from package.json file change the dependencies and set the version you want :
      "dependencies": {
        "eslint": "8.48.0",
        "eslint-config-next": "13.4.16",
        "next": "13.4.16",
        "react": "18.2.0",
        "react-dom": "18.2.0"
      }
    
    1. run npm install again

  2. You can try to downgrade your next version to 13.4.16

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