Next.js Discord

Discord Forum

useParams() returns null

Answered
Wetterhoun posted this in #help-forum
Open in Discord
WetterhounOP
Why does it returns null? What am I doing wrong? Here is the snippet code for the page.

P.S. pls don't judge my code. lol

"use client";

import { useParams, useRouter } from "next/navigation";

function Todos() {
   const { projectId } = useParams();
    ....
}

export default function ProtectedTodos() {
  return (
    <ProtectedPage>
      <Todos />
    </ProtectedPage>
  );
}
Answered by Ray
because useParams is for app router and you are using page router
View full answer

49 Replies

how does your url looks like? @Wetterhoun
Answer
WetterhounOP
http://localhost:3000/projects/1/todos
try using useRouter from next/router
import { useRouter } from 'next/router'
 
export default function Page() {
  const router = useRouter()
  return <p>Post: {router.query.projectId}</p>
}
@Ray because useParams is for app router and you are using page router
WetterhounOP
Damn. Why we can't have nice simple things?
because next needs to support both router?
Giant panda
you can use both
lol
Giant panda
:lolsob:
you need to use app router for it
WetterhounOP
That's sad.
I am using T3 stack.
kind of went ahead with the pages router.
T3 stack support app router now
WetterhounOP
Should I use pages or app router?
in your opinion.
I would use app router
over page router
WetterhounOP
is there any benefits to it?
Like what's new?
Giant panda
WetterhounOP
if you have to boil it down to a bumper sticker?
server component, less javascript sent to client
form action work without javascript enabled
WetterhounOP
too much for a bumper sticker.
btw, can I use nextjs without vercel?
sure
WetterhounOP
And if so, what will I losing?
losing the support from vercel maybe
WetterhounOP
like what functionality are tied to vercel.
like there is this opennext.
I don't know shit about either next or opennext
yes i have been using it
but It only support deploying to aws atm
WetterhounOP
Can I just simply throw T3 stack into a docker, deploy it on hetzner and call it a day?
sure
WetterhounOP
so it can be used without cloud functions and shit.
that's nice.
check out this dockerfile
Giant panda
deprecated
oh where did they move
here
WetterhounOP
noice.
thanks men