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

194
Vistas
How to send a variable from react to node

I'm a beginner, and I'm trying to figure out how to send a variable generated from a function in react to the backend server side.

The user clicks on a button and a json object called rowObject is generated in home.jsx . I want to send it to backend to post.js to save it to the database. How do I achieve this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your front end would make a request to your server, perhaps with something like the browsers built in fetch() function.

For example:

function MyComponent() {
  function onClick() {
    fetch(
      '/some/path/here',
      {
        method: 'POST',
        body: JSON.stringify({ myData: 123 })
      }
    )
  }

  return <div onClick={onClick}>Click Me</div>
}

Then on the backend in express you would have something like:

const express = require('express')
const app = express()
const port = 3000

app.post('/some/path/here', (req, res) => {
  dbOrSomething.saveSomewhere(req.body) // your implementation here
  res.send('Saved!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
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