Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从React.FC组件返回null_Javascript_Reactjs_Typescript_Eslint - Fatal编程技术网

Javascript 如何从React.FC组件返回null

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

我对ESLint和TypeScript感到困惑

我无法返回
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",
}