8

I want to make routes array and apply it on useRoutes from react-router@6. Currently I am using typescript and vite. But, i got error when try to assign my component to 'element' key.

type HelloWorld = /unresolved/ any
'HelloWorld' refers to a value, but is being used as a type here. Did you mean 'typeof HelloWorld'?ts(2749)
Parsing error: '>' 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)
}
2
  • What is HelloWorld in this context? minimal reproducible example Commented Jun 30, 2022 at 18:30
  • @DrewReese a component, sir. Commented Jun 30, 2022 at 18:35

1 Answer 1

20

Please make sure that your file has the .tsx file extension and is not just a .ts file.

Sign up to request clarification or add additional context in comments.

3 Comments

You're right. I missed it. Thank you.
Beautiful! I was thinking that my whole day will be spent on this debugging but resolved by just this thing.
In my case I needed to restart VS Code even though it was a TSX file from the beginning ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.