react速览

崮生的 react 速览

ref 选中 dom

function TextInputWithFocusButton() { const inputEl = useRef(null); const onButtonClick = () => { // `current` 指向已挂载到 DOM 上的文本输入元素 inputEl.current.focus(); }; return ( <> ); }

react/router 获取当前路由的 child (子路由) 选中的哪一个 route

typescript
const cur = route?.routes?.find((el) => matchPath(location.pathname, el))