我不知道如何为孩子分配类型
const RequireAuth = ({children}) => {
const location = useLocation();
const auth = false; //fake auth
if (!auth) {
return <Navigate to='/login' state={{from: location}} />
}
return children
}
这个我试过了,不行
const RequireAuth = ({children: object}) => ...
至少有两种方式
指定参数类型:
({children}: {children: ChildrenType}) => {({children}: ArgType) => {,ArgType带有字段的类型在哪里children指定函数类型
由于使用了react,因此可以将内置类型用于功能组件
FC