Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

451
Visualizações
useParams() not getting the userId and shows undefined in console when i console out userId

I am trying to access the userId of a user from the url (url looks something like this http://localhost:3000/user-profile/904900003354517617608).

when i console out the userId it shows undefined.

I have used useParams in some other components too and they work properly but for useProfile it is having some problem (also i am using sanity).

the code:

const UserProfile = () => {
    const [user, setUser] = useState(null)
    const [pins, setPins] = useState(null)
    const [text, setText] = useState('Created')
    const [activebutton, setActivebutton] = useState('created')

    const navigate = useNavigate()
    const { userId } = useParams()
    console.log(userId)


    useEffect(() => {
        const query = userQuery(userId)

        client.fetch(query)
            .then((data) => {
                setUser(data[0])
            })
    }, [userId]) 

    return (
        <div className="relative pb-2 h-full justify-center items-center">
            <div className="flex flex-col pb-5">
                <div className="relative flex flex-col mb-7">
                    <div className="flex flex-col justify-center items-center">
                        <img 
                            src={randomImage} 
                            className="w-full h-370 2xl:h-510 shadow-lg object-cover"
                            alt="Banner"
                        /> 

                        <img 
                            className="rounded-full w-20 h-20 -mt-10 shadow-xl object-cover"
                            src={user.image}
                            alt="Profile-picture"
                        />
                    </div>
                </div>
            </div>
        </div>
    )
}

export default UserProfile
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Make sure your route looks like this:

<Route path="/user-profile/:userId" />
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda