React JS JSX

React JS JSX

JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like code within JavaScript. It's primarily used with React to describe what the UI should look like. JSX makes it easier to write and understand the structure of UI components in React.

Article content
JSX


Here's a simple example of JSX code in a React component:

import React from 'react';

function MyComponent() {

return (

<div>

<h1>Hello, world!</h1>

<p>This is a JSX example.</p>

</div>

);

}

export default MyComponent;

In this example:

  • The <div> element is used to group the <h1> and <p> elements.
  • The <h1> element displays the text "Hello, world!".
  • The <p> element displays the text "This is a JSX example.".

JSX code can contain expressions inside curly braces {}. This allows you to embed JavaScript expressions within JSX. For example:

import React from 'react';

function MyComponent() {

const name = 'Sridhar';

return <h1>Hello, {name}!</h1>;

}

export default MyComponent;

In this example, the value of the name variable is inserted into the JSX output.








To view or add a comment, sign in

More articles by Sridhar Raj P

  • 100 React Native Project Ideas

    Beginner Level Projects Focus: UI building, state handling, basic components Counter App – Increment, decrement, reset…

  • React Native Learning Path (Beginning to Advanced)

    1. Beginning Level Goal: Learn the basics of React Native, Components, and run your first app.

    3 Comments
  • Employee Management System using Spring Boot

    Employee Management System – Manage employee records with CRUD operations Spring Boot 📝 Step 1: Set Up the Spring Boot…

    2 Comments
  • JavaScript Learning Path 🚀

    JavaScript Learning Path 🚀 This structured path will take you from JavaScript basics to advanced concepts, helping you…

    2 Comments
  • CSS Learning Path 🎨

    CSS Learning Path 🎨 This structured path will take you from CSS basics to advanced styling techniques, helping you…

  • HTML Learning Path 🌐

    HTML Learning Path 🌐 This structured path will guide you from HTML basics to advanced concepts, helping you build web…

  • Full Stack React JS + Spring Boot Learning Path

    Full Stack React JS + Spring Boot Learning Path 🚀 This structured path will help you master React JS for the frontend…

    4 Comments
  • Core Python Learning Path

    Core Python Learning Path 🐍 This path focuses on mastering Python fundamentals, essential for any Python-based career.…

    2 Comments
  • Python Learning Paths

    Python has multiple learning paths depending on your goals. Here are some structured learning paths for different…

    3 Comments
  • Custom Hook

    Custom Hooks are a powerful feature introduced in React 16.8 that allow developers to extract and reuse stateful logic…

Insights from the community

Others also viewed

Explore topics