How to Render React Component Without JSX?

Render React components without JSX using native APIs like React.createElement, helpful for dynamic rendering, advanced control, or simplified tooling.

Learn how to write and render React components without JSX.

Why Render Without JSX?

  • No build step: Useful in environments where Babel or a build tool isn’t available.
  • Dynamic rendering: Enables rendering components by name or from a mapping.
  • Behind the scenes: Helps you understand how JSX is compiled.

Rendering a React Component Without JSX

Here’s how you can do typical JSX syntax with raw React.createElement for control and clarity.

Basic Example

import React from 'react'; import ReactDOM from 'react-dom/client';   function Greeting({ name }) {   return React.createElement('h1', null, 'Hello ', React.createElement('i', null, name), '. Welcome!'); }   const root = ReactDOM.createRoot(document.getElementById('root')); root.render(React.createElement(Greeting, { name: 'Taylor' }));
This code renders the same UI as <Greeting name="Taylor" />, but without any JSX.

Dynamic Component Rendering (Mapping)

Suppose you want to render a component by name, not by direct import or JSX:

import React from 'react';import Login from './Login'; import Logout from './Logout';   const componentMap = {   Login,   Logout, };   function Popup({ componentName }) {   const ComponentToRender = componentMap[componentName];   return React.createElement(     'div',     null,     ComponentToRender       ? React.createElement(ComponentToRender)       : 'No component to display'   ); }
This pattern is powerful for modals, popups, or dashboards where the component is chosen at runtime.
Also Read: ReactJS Development Services : Shift Towards the Appealing UI

Tips & Gotchas

  • Props: Pass them as the second argument to createElement (e.g., { name: 'Taylor' }).
  • Children: Pass as additional arguments after props; you can nest createElement calls for nested elements.
  • Don’t call function components directly: Always use React.createElement(Component) instead of Component()—the latter breaks hooks and context.
  • Shorthand: Assign const e = React.createElement; for less typing in large files.

Advanced: No-JSX with Third-Party Helpers

  • react-hyperscript and hyperscript-helpers provide more concise, chainable syntax for large UIs without JSX.
  • No build step: Useful in environments where Babel or a build tool isn’t available.
  • Dynamic rendering: Enables rendering components by name or from a mapping.
  • Behind the scenes: Helps you understand how JSX is compiled.
Related

Why am I getting this problem? If you apply separate filters in sequence or only check one property at a time your code will match…

22 Oct, 2025

Why am I getting this problem? By default, rendering a table in React just displays data in its original order. Clicking the header won’t sort…

15 Oct, 2025

Understanding the Problem When building React applications, especially Single Page Applications (SPAs) using React Router, you might expect the page to scroll to the top…

10 Oct, 2025