简体   繁体   English

它的返回类型 'void' 不是有效的 JSX 元素

[英]Its return type 'void' is not a valid JSX element

在此处输入图像描述

// src/Login.tsx
const Login = () => {
  <h1>Success</h1>;
};

export default Login;

// src/Router.tsx
export default () => {
  const CLIENT_ID = process.env.REACT_APP_KAKAO_API_KEY;
  const REDIRECT_URI = "http://localhost:3000/api/user/kakao/callback";
  const KAKAO_AUTH_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code`;

  return (
    <Router>
      <div className="App">
        <Switch>
          <Route exact path="/">
            <h1>
              <a href={KAKAO_AUTH_URL}>
                <Login />
              </a>
            </h1>
          </Route>
          <Route path="/oauth/kakao/callback">
            <Auth />
          </Route>
          <Route path="/profile">
            <Profile />
          </Route>
        </Switch>
      </div>
    </Router>
  );
};

I see an error.. 'Login' cannot be used as a JSX component.Its return type 'void' is not a valid JSX element.我看到一个错误。“登录”不能用作 JSX 组件。它的返回类型“void”不是有效的 JSX 元素。

I tried to reference it on here, but I can't find a solution.我试图在这里引用它,但找不到解决方案。 What should I do?我应该怎么办?

Your login component needs return anything.您的登录组件需要返回任何内容。

// src/Login.tsx
const Login = () => {
  return <h1>Success</h1>;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 它的返回类型 &#39;void | Element&#39; 不是有效的 JSX 元素。 类型 &#39;void&#39; 不能分配给类型 &#39;Element | 空值&#39; - Its return type 'void | Element' is not a valid JSX element. Type 'void' is not assignable to type 'Element | null' 组件不能用作 JSX 组件。 它的返回类型 'void' 不是有效的 JSX 元素(React Hooks) - Component cannot be used as a JSX component. Its return type 'void' is not a valid JSX element (React Hooks) 不能用作 JSX 组件。 它的返回类型“void”不是有效的 JSX element.ts(2786) - cannot be used as a JSX component. Its return type 'void' is not a valid JSX element.ts(2786) 组件不能用作 JSX 组件。 它的返回类型'元素 | undefined' 不是有效的 JSX 元素 - Component cannot be used as a JSX component. Its return type 'Element | undefined' is not a valid JSX element “X”不能用作 JSX 组件。 它的返回类型 'Element[]' 不是有效的 JSX 元素 - 'X' cannot be used as a JSX component. Its return type 'Element[]' is not a valid JSX element 组件不能用作 JSX 组件。 它的返回类型 'Element[]' 不是有效的 JSX 元素 - Component cannot be used as a JSX component. Its return type 'Element[]' is not a valid JSX element 它的返回类型 'Element | undefined' 不是有效的 JSX 元素。 类型“undefined”不可分配给类型“Element | 无效的' - Its return type 'Element | undefined' is not a valid JSX element. Type 'undefined' is not assignable to type 'Element | null' 不能用作 JSX 组件 它的返回类型 string | 元素不是有效的 JSX 元素类型“string”不可分配给类型“Element | 无效的' - cannot be used as a JSX component Its return type string | Element is not a valid JSX element Type 'string' is not assignable to type 'Element | null' 它的实例类型“BrowserRouter”不是有效的 JSX 元素 - Its instance type 'BrowserRouter' is not a valid JSX element 具有 function 子项的组件产生错误“它的返回类型‘ReactNode’不是有效的 JSX 元素。” - Component with function child yields error "Its return type 'ReactNode' is not a valid JSX element."
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM