일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- built in object
- concept
- SSR
- tailwindcss
- hardhat
- error
- 기준
- CLASS
- solidity
- express.js
- REACT
- Props
- bitcoin
- evm
- blockchain
- node.js
- nextJS
- Interface
- HTML
- Redux
- API
- Ethereum
- graphQL
- 삶
- useState
- CSS
- web
- JavaScript
- middleware
- typeScript
- Today
- Total
ReasonJun
React : JSX (JavaScript XML) 본문
JSX (JavaScript XML) is an extension to the JavaScript language syntax used in React. It allows you to write HTML-like code within JavaScript, making it easier to define the structure and appearance of UI components in React.
With JSX, you can write HTML-like tags and include JavaScript expressions within curly braces {}. It provides a concise and intuitive way to define the UI hierarchy and the data bindings within the component.
Here's an example of JSX code in React:
import React from 'react';
const App = () => {
const name = 'John Doe';
const greeting = <h1>Hello, {name}!</h1>;
return (
<div>
{greeting}
<p>Welcome to my React app.</p>
</div>
);
};
export default App;
In the above code, we define a functional component named App. Within the component's return statement, we use JSX to define the UI structure. We can use HTML-like tags such as <div>, <h1>, <p>, etc., to create the desired HTML structure.
JSX also allows us to include JavaScript expressions within curly braces {}. In the example, we use the name variable to display a dynamic greeting message by embedding it within the <h1> tag.
Under the hood, JSX code is transformed into regular JavaScript function calls by a transpiler like Babel. The transpiler converts JSX tags and expressions into React createElement calls, creating a virtual representation of the UI components.
Using JSX provides several benefits in React development:
- Familiar Syntax: JSX resembles HTML, making it easier for developers with web development background to adopt React.
- Readability: JSX code is more readable and expressive compared to manipulating the DOM directly with JavaScript.
- Component Structure: JSX allows for nesting and composing components in a declarative manner, making it easier to understand the hierarchy and relationships between components.
- JavaScript Integration: JSX seamlessly integrates JavaScript expressions, allowing you to dynamically generate UI components based on data and logic.
- Compile-Time Safety: JSX code is checked and validated at compile-time, providing early detection of syntax errors and potential issues.
Overall, JSX enhances the development experience in React by combining the power of JavaScript with a familiar and intuitive syntax for defining UI components and their behavior.
'Frontend > React' 카테고리의 다른 글
React : state / props (0) | 2023.06.11 |
---|---|
React : Basic Rules for JSX (0) | 2023.06.11 |
React : Why use React? (Comparing javascript and react code) (0) | 2023.06.11 |
React : Why use React? (Declarative Syntax) (0) | 2023.06.11 |
React : Why use React? (Virtual DOM) (0) | 2023.06.11 |