As a fresher , I face an interview question - How can we write React code without JSX?
Loading
As a fresher , I face an interview question - How can we write React code without JSX?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raghunath BhukanRank #744 · 3.1K reputationPosted Jan 21, 2026, 6:28 AM EST
In React, JSX just simplifies the way you write or read code (Readable syntax) for
React.createElement. You can write React code without JSX by usingReact.createElementdirectly.1. Basic example with JSX
Normally, with JSX, you might write:
function App() { return ( Hello, React! This is a paragraph. ); }This JSX gets compiled to
React.createElementcalls behind the scenes.2. Equivalent code without JSX
Without JSX, you can write it like this:
import React from 'react'; import ReactDOM from 'react-dom/client'; function App() { return React.createElement( 'div', // Type of element null, // Props (null = no props) React.createElement('h1', null, 'Hello, React!'), React.createElement('p', null, 'This is a paragraph.') ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(React.createElement(App));Explanation:
React.createElement(type, props, ...children)type? HTML tag name or a React componentprops? an object containing properties/attributeschildren? the inner content or nested elementsNesting is done by passing other
React.createElementcalls as children.3. With props and events
For example, a button with a click handler:
function App() { function handleClick() { alert('Button clicked!'); } return React.createElement( 'button', { onClick: handleClick, style: { fontSize: '20px' } }, 'Click Me' ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(React.createElement(App));Notice how you pass props as an object, including event handlers and styles.
JSX is optional. React works fine with plain JS using
React.createElement.Each JSX tag is just a shorthand for
React.createElement.Nesting elements requires calling
React.createElementrecursively for each child.