Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda