How can I use the "keyword" from the params into my axios get request? My Approach is not working,
// Front End Code
const ComprasLista = () => {
const { keyword } = useParams();
const compras = useQuery("compras", ({ keyword = "" }) => {
return axios
.get(`https://582821e.sse.codesandbox.io/api/compras?keyword=${keyword}`)
.then((res) => res.data);
});
//
};
export default ComprasLista;
// Back End Code
router.get(
"/",
asyncHandler(async (req, res) => {
const keyword = req.query.keyword
? {
fornecedor: {
$regex: req.query.keyword,
$options: "i"
}
}
: {};
const compras = await Compras.find({ ...keyword });
res.json(compras);
})
);