import React, { useState, useEffect, useRef } from 'react'; import { useSearch, AnchorLink } from 'dumi/theme'; import './SearchBar.less'; export default () => { const [keywords, setKeywords] = useState(''); const [items, setItems] = useState([]); const input = useRef(); const result = useSearch(keywords); useEffect(() => { if (Array.isArray(result)) { setItems(result); } else if (typeof result === 'function') { result(`.${input.current.className}`); } }, [result]); return (
setKeywords(ev.target.value) } : {})} />
    {items.map(meta => (
  • setKeywords('')}> {meta.parent?.title && {meta.parent.title}} {meta.title}
  • ))}
); };