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

162
Views
Pasar un parámetro de pug a JSX

Estoy construyendo un juego usando Express y React. Necesito acceder al ID de usuario en mi archivo index.jsx para realizar acciones en mis controladores, como incrementar la puntuación del usuario.

Mi ruta representa un archivo index.pug mientras pasa un parámetro user_id :

 //server.js app.get('/', function (req, res) { const userId = req.query.userId res.render('index', {userId: userId}) })

Entonces puedo acceder al userId de usuario en mi archivo pug, así:

 // index.pug body div#errors #root p #{userId} // prints the User Id

Ahora necesito acceder a este userId de ID de usuario en mi archivo index.jsx que contiene los componentes de React.

 class Cell extends React.Component { render() { return ( <button onClick={() => this.props.onClick()}> {userId} </button> ) } }

Pero eso no funciona, como esperaba. ¿Algunas ideas?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puedes hacerlo usando el objeto de window

Digamos en tu archivo .pug

 script. var userId = '#{userId}'; //assigning pug value to window object.

Ahora puede acceder al ID de window.userId en el componente de react como userId

 class Cell extends React.Component { render() { return ( <button onClick={() => this.props.onClick()}> {window.userId} </button> ) } }
over 4 years ago · Santiago Trujillo 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!