🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)
🔧 AI Nachrichten Major AI platforms go down in unprecedented simultaneous outage(03.09.2026 um 17:34 Uhr)
🔧 AI Nachrichten ChatGPT, Claude, and Grok Down? Users Report Widespread Outages(03.09.2026 um 19:14 Uhr)
🔧 AI Nachrichten OpenAI Launches GPT-6 Astra, Says We May Have Entered the AGI Era(03.09.2026 um 22:08 Uhr)
🔧 AI Nachrichten Claude Comes to CarPlay as Fifth Major AI Chatbot App(05.09.2026 um 05:31 Uhr)
🔧 AI Nachrichten OpenAI’s GPT-6 Astra Is AGI, Says NVIDIA CEO Jensen Huang(07.09.2026 um 06:31 Uhr)
🔧 AI Nachrichten Blame AI companies for Mac mini and Mac Studio shortage(31.08.2026 um 10:32 Uhr)

🔧 Programmierung 🕛 kürzlich 5 Min Lesezeit
0

Converting HTML to JSX : JSX and Rules of JSX

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

We will learn what JSX is and the rules of JSX.






JSX is a syntax extension for JavaScript. You can write HTML-like formatting inside a JavaScript file.



It is based on Web, Html, Css and JavaScript. web developers wrote the content of the page separately as an Html file, the designs as a Css file, and the logic as a JavaScript file.





  • Need to know : JSX is a syntax extension, while React is a JavaScript library.




CODE

<div class="wrapper">HTML</div>










CODE

//CSS

.wrapper {
display : flex;
}










CODE

function myFunction() {
document.getElementById("wrapper").innerHTML = "Hello world";
}










But as the Web has become more interactive, logic has become more important. JavaScript was managing Html. Therefore, in React, logic and formatting live together in components.




React component example :




CODE
import React, { useState } from "react";

function App() {
const [formData, setFormData] = useState({
username: "",
password: "",
});

const handleChange = (event) => {
const { name, value } = event.target;
setFormData((prevState) => ({ ...prevState, [name]: value }));
};

return (
<form>
<label>
Username:
<input
type="text"
name="username"
value={formData.username}
onChange={handleChange}
/>
</label>
<label>
Password:
<input
type="password"
name="password"
value={formData.password}
onChange={handleChange}
/>
</label>
<input type="submit" value="Submit" />
</form>
);
}









it is important to keep the rendering markup and logic together to keep an html tag in sync with each other with each editing.



React components are a JavaScript function that contains the markup that React rendering in the browser. React components use a syntax extension called JSX for this markup. JSX is looks like to Html.







The Rules of JSX



1. Return a single root element



To return elements from a component, wrap them with a single parent tag. You can use a or fragment (<></>)

For example div



CODE
<div>
<h1>Hedy Lamarr's Todos</h1>
<img
src="https://picsum.photos/200/300"
alt="lorempicsum"
>
</div>







For example <></>



CODE
<>
<h1>Hedy Lamarr's Todos</h1>
<img
src="https://picsum.photos/200/300"
alt="lorempicsum"
/>
</>








  • Fragments let you group things without leaving any trace in the browser HTML tree.






2. Close all the tags



In JSX, all tags must be closed. For example, self-closing tags such as img in Html



Example :



CODE
<img 
src="https://picsum.photos/200/300"
alt="lorempicsum"
/>







3. camelCase



In React, many HTML properties are written with camelCase.



Example :



CODE
 <img 
src="https://picsum.photos/200/300"
alt="lorempicsum"
className="photo"
/>

<button onClick={handleClick}>Click Me</button>











JavaScript in JSX



In JSX, sometimes you will want to add a little JavaScript logic or refer to a dynamic feature inside this markup. In this case, you can use brackets in JSX




  • Passing the string attribute to JSX



When you want to pass a string attribute to JSX, you put it in single or double quotes



Example :



CODE
export default function Avatar() {
return (
<img
className="avatar"
src="https://picsum.photos/200/300"
alt="lorempicsum"
/>
);
}







Here, src and alt are being passed as strings. but if you want to specify the src or alt text dynamically, you can use a value from javascript using curly braces instead of double quotes



Example :



CODE
export default function Avatar() {
const avatar = 'https://picsum.photos/200/300';
const description = 'lorempicsum';
return (
<img
className="avatar"
src={avatar}
alt={description}
/>
);
}









  • Using Curly Braces



It is possible to use JavaScript with curly braces {}. You can use functions, variables and more.



Example :



CODE
import React, { useState } from 'react';
const content = 'Toggle Text';
function ToggleText() {
const [isVisible, setIsVisible] = useState(true);

return (
<div>
{isVisible && <p>This text is toggleable</p>}
<button onClick={() => setIsVisible(!isVisible)}>
{content}
</button>
</div>
);
}

export default ToggleText;








  • Using Double Curlies Braces



React does not require you to use inline styles (CSS classes work great for most cases). But when you need an inline style, you can pass an object to the style attribute. Use double curlies braces.



Example :



CODE
export default function TodoList() {
return (
<ul style={{
backgroundColor: 'black',
color: 'pink'
}}>
<li>lorem ipsum</li>
</ul>
);
}








  • You see {{ }} in JSX, know that it’s object inside the JSX curlies.


  • Inline style properties should be write as camelCase.







You can move several expressions into one object, and use them in your JSX inside curly braces



CODE
const person = {
name: 'Gregorio Y. Zara',
theme: {
backgroundColor: 'red',
color: 'yellow'
}
};

export default function TodoList() {
return (
<div style={person.theme}>
<h1>{person.name}'s Todos</h1>
</div>
);
}












Conclusion



JSX is an important tool that makes web development processes more effective and practical. With JSX, you can keep the render markup and logic together to keep an html Decal synchronized with each other in every edit.






If you like my articles, you can buy me a coffee :)

Image description

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
GPT-6 Astra Release Today? OpenAI’s Next Major AI Model Is Almost Here
1 Quelle
Apple accuses OpenAI of destroying evidence as trade-secrets fight intensifies
1 Quelle
Major AI platforms go down in unprecedented simultaneous outage
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Converting HTML to JSX : JSX and Rules of JSX

Thematisch verwandte Begriffe: Converting, HTML, Rules · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...