I like to use only placeholder without label for inputs/forms. Therefore i created a onClick -> set type from text to date. But if someone has a bad memory and dont know what date to fill in, I created a onMouseleave -> set type from date to text, if its empty. But if someone want to fill his birthday and the mouse leaves accendently, they will give me a text instead of a date. Therefore I want to use a setTmeout but it doesn't work as planned.
const [type, setType] = useState("text")
const handleDate = () => {
setType("date")
}
const handleText = () =>{
if(values.birthday === ""){
setType("text")}
}
<input
onChange={handleChange}
value={values.birthday}
type={type}
name="birthday"
placeholder="birthday"
onClick={handleDate}
onMouseLeave={setTimeout(handleText, 3000)}/>
by using onMouseLeave={setTimeout(handleText, 3000)}/> the input field is deselected and i can't type anything in.
I want that the if-query will be checked after 3 seconds and am able to type something in