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

115
Views
How to make request on Axios by ID

i'm coding a MERN delivery app i na basic lvl and need a simple back-end. I'm geting all data from database in front-end part by axios

    const [products, setProducts] = useState([]);
    useEffect(()=>{
    axios.get('api/products')
     .then(res => {
         console.log(res)
         setProducts(res.data)
     })
    .catch(err => {
        console.log(err)
    })

})

also I need to get my product to shoping bucket, but dont understand how to do this. This is code work only in front-ent, but when i get my data from database - this code stop working

 let [cartItems, setCartItems] = useState([])

 const addProduct = (product) => {
 const productExist = cartItems.find(item => item.id === product.id)
 if (productExist) {
    setCartItems(cartItems.map(item => item.id === product.id?
        {...productExist, quantity: productExist.quantity + 1}: item));
 } else {
    setCartItems([...cartItems, {...product, quantity: 1}])
ja }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

axios.get(`api/products/${productId}`)
     .then(res => {
         console.log(res)
         setProducts(res.data)
     })
    .catch(err => {
        console.log(err)
    })
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!