Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda