I need to take the forma data submitted in ReactJS (JSX) and submit it to the app.post method in my Express API backend. I've looked for ages on how to do this, but I still have no idea.
My front-end form code:
import React, { Component } from 'react'
import '../public/styles/App.css'
import Header from "./header.js"
export default class Login extends Component {
render() {
return(
<div style={{border:"none"}}>
<div style={{background:"white"}}>
<br></br>
<center><Header /></center>
<br></br>
</div>
<br></br>
<br></br>
<div style={{background:"white"}}>
<center><form>
<br></br>
Username: <br></br>
<input type = "text" name= "username"></input>
<br></br>
<br></br>
Password: <br></br>
<input type = "text" name = "password"></input>
<br></br>
<br></br>
<input type = "submit" value = "Log-in"></input>
<br></br>
</form></center>
<br></br>
</div>
</div>
)
}
}
Express post method:
app.post("/api/login", async(req, res) => {
const id = await users.login(req.body.user, req.body.pass)
console.log(id)
Not sure what params the express post needs to take it, or how to send it via the component in ReactJS. Any rough idea on how to send form data from ReactJS to NodeJS Express api would be great!