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

136
Views
How can I pass the current logged in user credentials eg the username to the props?

I wish to get the username and user ID of the current logged in user and pass them to the <Comments /> component as props. Currently I have hard code the the values like this <Comments username='Vincent', user_id=1. How do I automat this process, so that the values are passed automatically depending on the current logged in user?

In my CommentsApp I have this:

... 
import Comments from './Comments'


const CommentsApp = () => {
    const [backendComments, setBackendComments] = useState([])
    // console.log('backendComments', backendComments)

    useEffect(() => {
        axios.get('http://127.0.0.1:8000/api/comments/')
            .then(res => {
                setBackendComments(res.data)
            })
            .catch(err => {
                console.log(err)
            })
    }, [])

    return (
        <div>
            <Comments user_id='1' username='Vincent' />
        </div>
    );
}

export default CommentsApp;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As T.J. Crowder has suggested, you could save your user's informations in React Context when he signs in. You could then access them in your CommentsApp component using the useContext hook.

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!