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>

Of course, I can’t render it as <…


This content originally appeared on DEV Community and was authored by me nefcanto

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>

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?


This content originally appeared on DEV Community and was authored by me nefcanto


Print Share Comment Cite Upload Translate Updates
APA

me nefcanto | Sciencx (2024-11-06T08:51:10+00:00) Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?. Retrieved from https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/

MLA
" » Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?." me nefcanto | Sciencx - Wednesday November 6, 2024, https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/
HARVARD
me nefcanto | Sciencx Wednesday November 6, 2024 » Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?., viewed ,<https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/>
VANCOUVER
me nefcanto | Sciencx - » Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/
CHICAGO
" » Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?." me nefcanto | Sciencx - Accessed . https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/
IEEE
" » Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate?." me nefcanto | Sciencx [Online]. Available: https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/. [Accessed: ]
rf:citation
» Can you please explain why React does not allow simple JSX variables to be used as components to reduce the boilerplate? | me nefcanto | Sciencx | https://www.scien.cx/2024/11/06/can-you-please-explain-why-react-does-not-allow-simple-jsx-variables-to-be-used-as-components-to-reduce-the-boilerplate/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.