Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

Fetch search results for the view

To utilize this search API in the frontend, we will set up a method that constructs the URL with query parameters and calls a fetch to make a request to the search product API. This fetch method will be defined as follows.

mern-marketplace/client/product/api-product.js:

import queryString from 'query-string'const list = (params) => {  const query = queryString.stringify(params)  return fetch('/api/products?'+query, {    method: 'GET',  }).then(response => {    return response.json()  }).catch((err) => console.log(err))}

In order to construct the query parameters in the correct format, we will use the query-string node module, which will help stringify the params object into a query string that can be attached to the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content