import React, { useState, useRef } from "react"; import { Link, useHistory } from "react-router-dom"; import useKeyboardShortcut from "use-keyboard-shortcut"; const Title: React.FC = () => { const [search, setSearch] = useState(); const [canSubmit, setCanSubmit] = useState(false); const history = useHistory(); const handleChange: React.ChangeEventHandler = (e) => { setCanSubmit(e.target.value.trim().length > 0); setSearch(e.target.value.trim()); }; const handleSubmit: React.FormEventHandler = (e) => { e.preventDefault(); if (!canSubmit) { return; } history.push(`/search?q=${search}`); }; const searchRef = useRef(null); useKeyboardShortcut(["/"], () => { searchRef.current?.focus(); }); return (
An otter scanning Otterscan
); }; export default React.memo(Title);