38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
import { useState } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { useEffect } from 'react';
|
|
|
|
|
|
const ResearchBar = () => {
|
|
|
|
const navigate = useNavigate();
|
|
const [value, setValue] = useState("");
|
|
|
|
|
|
const search = async (query) => {
|
|
navigate('/morceaux', { state: { query: query } });
|
|
}
|
|
|
|
const handleValueChange = async (value) => {
|
|
setValue(value);
|
|
}
|
|
|
|
return (
|
|
<div className="research-container">
|
|
<input className="research-input"
|
|
onKeyDown={(e) => {
|
|
if (e.key === "Enter") {
|
|
search(value);
|
|
}
|
|
}}
|
|
value={value}
|
|
onChange={(e) => handleValueChange(e.target.value)}
|
|
placeholder="Rechercher..."></input>
|
|
<button className="research-btn" onClick={() => search(value)}>
|
|
<div className="fa fa-search" />
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default ResearchBar; |