SearchBar presque fonctionnelle, Featured qui va fetcher dans la bd

This commit is contained in:
MarcEricMartel
2022-10-26 11:29:57 -07:00
parent e40807b6a2
commit 04c7d68a44
5 changed files with 29 additions and 34 deletions

View File

@@ -1,18 +1,18 @@
import { useState } from 'react';
import { Navigate } from 'react-router-dom';
async function fetchData(query, preview) {
const response = await fetch(`https://localhost:7292/api/Search?query=${query}&preview=${preview}&deep=true`);
const json = await response.json();
// if (json.length > 0)
// setProducts([...json]);
return { json };
}
function useInput(defaultValue) {
const [value, setValue] = useState(defaultValue);
function onChange(e) {
setValue(e.target.value);
fetchData(value, true);
if (value.length > 1)
fetchData(value, true);
}
return {
value,
@@ -25,8 +25,8 @@ const ResearchBar = () => {
return (
<div className="research-container">
<input className="research-input" placeholder="Rechercher..." {...input}></input>
<button className="research-btn">
<div className="fa fa-search" onClick={fetchData(input.value, false)}/>
<button className="research-btn" /*onClick={fetchData(input.value, false)}*/>
<div className="fa fa-search" />
</button>
</div>
);