0
export default function course() {
  const router = useRouter()
  slu= router.asPath.split("/")[2]
  console.log(slu)
  return (<design goes here>);
}

So the problem here is that when I use this method it gives me this output enter image description here

What I want is the value 1731547675 but instead of that it's giving me [slug] What's wrong that I am doing here

Saksham Kushwaha
  • 274
  • 1
  • 18

1 Answers1

1

It Prints multiple times because the ui is refreshed everytime You set a state Wrap Your Console.log into a useEffect block

const [slu, setslu] = useState(0);
useEffect(()=>
  setslu(router.asPath.split("/")[2])
}

Hopefully this helps. Note: Use const instead of let in creating a state