Enterprise Verified
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Core Syntax 7 min read • Chapter 7 of 26

React JSX

What is JSX? Rules for writing JSX, embedding JavaScript expressions with curly braces, Fragment syntax, and attribute differences.

JSX stands for JavaScript XML. JSX allows us to write HTML in React, making it easier to write and add HTML in React.

Key Rules of JSX

  • Single Root Element: Use React Fragments (<>...</>) to group multiple elements.
  • className: Use className instead of class because class is a reserved keyword in JavaScript.
  • Self-closing tags: All empty tags must close with a forward slash: <input />, <img />.

Example

<!DOCTYPE html>
<html>
<head>
    <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body style="font-family:sans-serif;padding:20px;">
    <div id="root"></div>
    <script type="text/babel">
        function Calculation() {
            const basic = 60000;
            const epf = basic * 0.12;
            return (
                <div style={{background: "#ecfdf5", padding: "16px", borderRadius: "10px", color: "#065f46"}}>
                    <h3>JSX Expression Evaluation</h3>
                    <p>Basic Salary: ₹{basic.toLocaleString()}</p>
                    <p>EPF Contribution (12%): ₹{epf.toLocaleString()}</p>
                    <p>Net Pay: ₹{(basic - epf).toLocaleString()}</p>
                </div>
            );
        }
        ReactDOM.createRoot(document.getElementById("root")).render(<Calculation />);
    </script>
</body>
</html>
Try it Yourself >> Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php

Community Q&A & Discussion

No questions yet. Be the first to start the discussion!
Enterprise Operations Suite

Streamline Employee Payroll & Attendance Operations

Eliminate manual spreadsheet errors. Integrate automated attendance tracking, EPF/ESI statutory calculations, and custom GST invoices.

Copied!

AI Learning Assistant

Ready to explain & guide

Hello! I am your MBS Digital AI Tutor. Ask me to explain concepts, review code, or suggest debugging steps.

Quick Starters:
AI Tutor is thinking...