Javascript 如何从React.FC组件返回null
我对ESLint和TypeScript感到困惑 我无法返回Javascript 如何从React.FC组件返回null,javascript,reactjs,typescript,eslint,Javascript,Reactjs,Typescript,Eslint,我对ESLint和TypeScript感到困惑 我无法返回null,因为ESLint:使用undefined而不是null(unicorn/no null) 好的,我不介意,将null更改为undefined。现在我有更多的错误 ESLint:不要使用无用的未定义的(独角兽/无无用的未定义)和 TS2322:类型“({testId,authType}:PropsWithChildren)=>元素|未定义”不可分配给类型“FC”。类型“Element | undefined”不可分配给类型“Rea
null
,因为ESLint:使用undefined
而不是null
(unicorn/no null)
好的,我不介意,将null
更改为undefined
。现在我有更多的错误
ESLint:不要使用无用的未定义的(独角兽/无无用的未定义)和
TS2322:类型“({testId,authType}:PropsWithChildren)=>元素|未定义”不可分配给类型“FC”。类型“Element | undefined”不可分配给类型“ReactElement | null”。类型“undefined”不可分配给类型“ReactElement | null”
const AuthForm:React.FC=({testId='',authType})=>{
开关(authType){
案例“登录”:
返回;
案例“变更通行证”:
返回;
“新通行证”案例:
返回;
违约:
返回null;
}
};
如何处理
提前谢谢 我认为您应该关闭unicorn/no null
规则,React组件不能返回未定义
const AuthForm: React.FC<Props> = ({ testId = '', authType }) => {
switch (authType) {
case 'logIn':
return <LogIn testId={testId} />;
case 'changePass':
return <ChangePass testId={testId} />;
case 'newPass':
return <NewPass testId={testId} newPassStatus="resetPass" />;
default:
return null;
}
};
{
"unicorn/no-null": "off",
}