2

I am using react router v6 and I want to render a component stored in a variable. In earlier versions of react router they have component props that allows you to render a component using a variable without the JSX syntax, however the V6 doesn't allow that.

import ComponentName from "components/ComponentName"
...
const component = ComponentName;
...
<Router path="..." element={component } />
1
  • Please do not edit solution announcements into the question or title. Accept (i.e. click the "tick" next to it) one of the existing answer, if there are any. You can also create your own answer, and even accept it, if your solution is not yet covered by an existing answer. See Can I answer my own question? Commented May 27, 2022 at 17:47

1 Answer 1

2

you can call your variable as a function

import ComponentName from "components/ComponentName"
...
const component = ComponentName;
...
<Router path="..." element={component()} />
Sign up to request clarification or add additional context in comments.

Comments

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.