Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

441
Views
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 answers
Answer question

0

Make sure your route looks like this:

<Route path="/user-profile/:userId" />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!