I am doing my first Ecommerce MERN stack project but i donot know how to make search component that will take the search input and return array of matching products
CodePudding user response:
If you want to make it fast you can get a graphic library like Material UI : https://mui.com/
Like this you can use pre-created components like this one that have autocomplete: https://mui.com/components/autocomplete/#search-input
You don't tell a lot of details about your case but to use it, you have to configure a route that returns you a list of the researched input everytime there is a change in this said input (configure the onChange function of the input section to request the list everytime there is a change).
CodePudding user response:
To add a search:
- Render your search bar component in the app
- Add your HTML elements
- Add a list of posts
- Filter the list based on your search query
- Adding immediate search or “search as you type”
- Adding SPA navigation with React Router
- “Search as you type”, SPA navigation and accessibility concerns
- Testing your component with React Testing Library
- Conclusion
If you want to know more precisely, you can view and understand the related material at the following URL. https://www.emgoto.com/react-search-bar/
Best regards.
