SearchBar pas encore fonctionnelle.
This commit is contained in:
parent
cdd0927796
commit
a145505fdb
@ -1,12 +1,32 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
|
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]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function useInput(defaultValue) {
|
||||||
|
const [value, setValue] = useState(defaultValue);
|
||||||
|
function onChange(e) {
|
||||||
|
setValue(e.target.value);
|
||||||
|
fetchData(value, true);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const ResearchBar = () => {
|
const ResearchBar = () => {
|
||||||
|
const input = useInput();
|
||||||
return (
|
return (
|
||||||
<div className="research-container">
|
<div className="research-container">
|
||||||
<input className="research-input" placeholder="Rechercher..."></input>
|
<input className="research-input" placeholder="Rechercher..." {...input}></input>
|
||||||
<button className="research-btn">
|
<button className="research-btn">
|
||||||
<div className="fa fa-search"/>
|
<div className="fa fa-search" onClick={fetchData(input.value, false)}/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user