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

188
Views
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 answers
Answer question

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 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!