簡體   English   中英

(React Typescript)“組件”指的是一個值,但在這里被用作一個類型。 您的意思是“typeof 組件”嗎?

[英](React Typescript) 'Component' refers to a value, but is being used as a type here. Did you mean 'typeof Component'?

我想制作路由數組並將其應用到 react-router@6 的 useRoutes 上。 目前我正在使用打字稿和 vite。 但是,當我嘗試將我的組件分配給“元素”鍵時出現錯誤。

鍵入 HelloWorld = /未解決/ 任何
'HelloWorld' 指的是一個值,但在這里被用作一個類型。 您的意思是“typeof HelloWorld”嗎?ts(2749)
解析錯誤:'>' expected.eslint

import { useRoutes, RouteObject } from "react-router-dom"

import { HelloWorld } from "@/HelloWorld"

export function Router (): ReturnType<typeof useRoutes> {
  const routes: RouteObject[] = [
    {
      path: "hello-world",
      element: <HelloWorld />
    }
  ]

  return useRoutes(routes)
}

請確保您的文件具有.tsx文件擴展名,而不僅僅是.ts文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM