[英]'children' is missing in props validation react/prop-types
I know this has been asked a few times but the current answers do not help me.我知道这已被问过几次,但目前的答案对我没有帮助。
I am using auth0
to do some authentication work.我正在使用
auth0
进行一些身份验证工作。 I just intalled esLint
and suddenly I am getting linting issues that I am unfamiliar with.我刚刚安装了
esLint
,突然间我遇到了我不熟悉的 linting 问题。
Right now this code:现在这段代码:
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
}
Is getting this error:收到此错误:
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
I tried to import PropTypes
but that doesn't seem to help (not sure if I was doing it right.)我尝试导入
PropTypes
但这似乎没有帮助(不确定我是否做得对。)
Thanks for any help!谢谢你的帮助!
You have to declare the propTypes in function.您必须在function中声明 propTypes。 Please check more details here
请在此处查看更多详细信息
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.