react-version #1

Merged
memartel merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
Showing only changes of commit a145505fdb - Show all commits

View File

@@ -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 input = useInput();
return (
<div className="research-container">
<input className="research-input" placeholder="Rechercher..."></input>
<input className="research-input" placeholder="Rechercher..." {...input}></input>
<button className="research-btn">
<div className="fa fa-search"/>
<div className="fa fa-search" onClick={fetchData(input.value, false)}/>
</button>
</div>
);