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

99
Views
Búsqueda de productos haciendo clic en el botón de búsqueda

Quiero buscar mi producto para mostrarlo en mi navegador haciendo clic en el botón de búsqueda.

Puedo buscar productos por Postman API muy bien. Pero no tengo idea de mostrar datos haciendo clic en el botón de búsqueda.

producto.js

 router.get("/find/:id", async (req, res) => { try { const product = await Product.findById(req.params.id); res.status(200).json(product); } catch (err) { res.status(500).json(err); } }); //GET ALL PRODUCTS router.get("/", async (req, res) => { const qNew = req.query.new; const qCategory = req.query.category; try { let products; if (qNew) { products = await Product.find().sort({ createdAt: -1 }).limit(1); } else if (qCategory) { products = await Product.find({ categories: { $in: [qCategory], }, }); } else { products = await Product.find(); } res.status(200).json(products); } catch (err) { res.status(500).json(err); } });

Navbar.js

 const Navbar = () => { return ( <Button>Search</Button> ); }; export default Navbar;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Vas a querer usar Axios para hacer una solicitud desde tu aplicación de reacción.

Para hacer esto, debe instalar y requerir Axios en su aplicación de reacción.

Este código le permitirá realizar una solicitud a su aplicación express:

 async function getProduct(productID) { try { const response = await axios.get(`/find/${productID}`); console.log(response); } catch (error) { console.error(error); } }

Esto solo funcionará cuando sepa cuál es la identificación del producto que está buscando. Si tiene otro punto final en su servidor para buscar un producto por nombre, puede cambiar el punto final en consecuencia. Aquí están los documentos de Axios.

Espero que esto ayude. ¡Gracias!

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!