React Core & Hooks (407 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)
What is the reason behind multiple JSX tags to be wrapped?
junior LevelCode ExampleFormsPerformance
Behind the scenes, JSX is transformed into plain javascript objects. It is not possible to return two or more objects from a function without wrapping into an array. This is the reason you can't simply return two or more JSX tags from a function without wrapping them into a single parent tag or a Fragment.
Practical Code Example
jsx
// Why multiple JSX tags must be wrapped:
// JSX transpiles to a function call: React.createElement(type, props, ...children).
// A JavaScript function can only return ONE expression or value.