📅  最后修改于: 2022-03-11 14:48:35.853000             🧑  作者: Mango
import { useRef, useLayoutEffect } from "react";
//HTMLInputElement || define the type of element
const element = useRef(null);
useLayoutEffect(() => {
//object can be null
if (element.current !== null) {
element.current.focus();
}
});