DEV Community

me nefcanto
me nefcanto

Posted on

Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?

Let's say I have static JSX content that I want to reuse across my website.

const Contacts = <div>
    <div>+1 111 11 11</div>
    <div>company at server.com</div>
</div>
Enter fullscreen mode Exit fullscreen mode

Of course, I can't render it as <Contacts />. I however can render it as {Contacts}.

Can you please tell me why should I add boilerplate code to this JSX constant to be able to render it like <Contacts />?

I'm curious about the technical why part. What prevented React developers to enable it?

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more