道具验证反应/道具类型中缺少'children'



我知道这个问题已经被问过几次了,但目前的答案对我没有帮助。

我正在使用auth0进行一些身份验证工作。我刚刚输入了esLint,突然间我遇到了一些我不熟悉的问题。

现在这个代码:

import React from 'react'
import { useAuth0 } from '@auth0/auth0-react'
const isAuthenticated = () => {
const { isAuthenticated } = useAuth0()
return isAuthenticated
}
export function IfAuthenticated({ children }) {
return isAuthenticated() ? <>{children}</> : null
}
export function IfNotAuthenticated({ children }) {
return !isAuthenticated() ? <>{children}</> : null
}

正在获取此错误:

src/components/Authenticated.jsx
Line 9:35:   'children' is missing in props validation  react/prop-types
Line 14:38:  'children' is missing in props validation  react/prop-types

我试图导入PropTypes,但这似乎没有帮助(不确定我做得是否正确。(

谢谢你的帮助!

您必须在函数中声明propTypes。请在此处查看更多详细信息

import PropTypes from 'prop-types';
export function IfAuthenticated({ children }) {
IfAuthenticated.propTypes = {
children: PropTypes.any
};
return isAuthenticated() ? <>{children}</> : null
}
export function IfNotAuthenticated({ children }) {
IfNotAuthenticated.propTypes = {
children: PropTypes.any
};
return !isAuthenticated() ? <>{children}</> : null
}

最新更新