From a145505fdb8c2e83de19185f8cc4e3b4144496f1 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:13:18 -0700 Subject: [PATCH] SearchBar pas encore fonctionnelle. --- .../src/components/ResearchBar.js | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js b/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js index e087b7a..8bd1773 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/ResearchBar.js @@ -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 (
- +
);