Vencovsky
Vencovsky

Reputation: 31625

How to get the reference element of a div in react?

If I have a component, like

function Foo(){
    return <h1>Hey</h1>
}

What I can do is something like

const MyElement = Foo
return (<MyElement />)

But How can I get this reference of a div element?

I want to do something like

const WrapComponent = foo ? MyComponent : div
...
<WrapComponent>
    {/*anything*/}
</WrapComponent>

I just don't know how do that with a div element.

Upvotes: 0

Views: 148

Answers (1)

Dan
Dan

Reputation: 10538

DOM elements like that are written as strings.

const WrapComponent = foo ? MyComponent : "div";

...
<WrapComponent>
  ...
</WrapComponent>

Upvotes: 1

Related Questions