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

215
Views
params in url undefined - axios, react, express

I'm trying to delete some data from a mysql database with the code:

app.delete("/api/deleteHomework/:homeworkName", (req, res) => {
    const homeworkName = req.params.homeworkName

    connection.query(
            "DELETE FROM homework WHERE name = ?",
            [homeworkName],
            (err, result) => {
                if(result){
                    res.send({ message: result })
                    console.log(result)
                }
                if(err){
                    console.log(err)
                }
            }
    )
})

and then the homeworkName is passed from the front end with the code:

  const deleteHw = (homework) => {
        Axios.delete(`http://localhost:1337/api/deleteHomework/${homework}`)
        .then((response) => {
            if(response){
                console.log(response)
            } else{
                console.log("error")
            }
        })
    }

<DeleteForeverIcon className={classes.deleteHwIcon} onClick={() => {deleteHw(value.homeworkName)}} />

However it says the params in the url is undefined: url: "http://localhost:1337/api/deleteHomework/undefined"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pass the props "value" directly in the delete function

export default function YourComponent({ value }) {
...

const deleteHw = () => {
  Axios.delete(`http://localhost:1337/api/deleteHomework/${value.homeworkName}`) // here
  .then((response) => {
    if(response){
      console.log(response)
    } else{
      console.log("error")
    }
  })
}
    
<DeleteForeverIcon className={classes.deleteHwIcon} onClick={deleteHw} />

Back side

app.delete('/api/deleteHomework/:homeworkName', (req, res) => {
  connection.query(`DELETE FROM homework WHERE name=${req.params.homeworkName}`, (err, result) => {
    if (err) {
      console.log(err);
    } else {
      res.json(result);
    }
  });
});
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!