You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Drop Writing Markup with JSX translation (already claimed by @kazz54)
Restores the English original for this page to avoid duplicating
@kazz54's claimed work on the sw.react.dev progress issue (#1).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/content/learn/writing-markup-with-jsx.md
+44-44Lines changed: 44 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,24 @@
1
1
---
2
-
title: Kuandika Markup kwa JSX
2
+
title: Writing Markup with JSX
3
3
---
4
4
5
5
<Intro>
6
6
7
-
*JSX*ni kiendelezi cha sintaksia cha JavaScript kinachokuwezesha kuandika markup inayofanana na HTML ndani ya faili ya JavaScript. Ingawa kuna njia nyingine za kuandika components (vipengele), watengenezaji wengi wa React hupendelea ufupi wa JSX, na misingi mingi ya msimbo huitumia.
7
+
*JSX*is a syntax extension for JavaScript that lets you write HTML-like markup inside a JavaScript file. Although there are other ways to write components, most React developers prefer the conciseness of JSX, and most codebases use it.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*Kwa nini React huchanganya markup na mantiki ya ku-render
14
-
*Jinsi JSX inavyotofautiana na HTML
15
-
*Jinsi ya kuonyesha taarifa kwa JSX
13
+
*Why React mixes markup with rendering logic
14
+
*How JSX is different from HTML
15
+
*How to display information with JSX
16
16
17
17
</YouWillLearn>
18
18
19
-
## JSX: Kuweka markup ndani ya JavaScript {/*jsx-putting-markup-into-javascript*/}
19
+
## JSX: Putting markup into JavaScript {/*jsx-putting-markup-into-javascript*/}
20
20
21
-
Wavuti imejengwa juu ya HTML, CSS, na JavaScript. Kwa miaka mingi, watengenezaji wa wavuti waliweka maudhui katika HTML, muundo katika CSS, na mantiki katika JavaScript—mara nyingi katika faili tofauti! Maudhui yaliwekewa markup ndani ya HTML huku mantiki ya ukurasa ikikaa kando katika JavaScript:
21
+
The Web has been built on HTML, CSS, and JavaScript. For many years, web developers kept content in HTML, design in CSS, and logic in JavaScript—often in separate files! Content was marked up inside HTML while the page's logic lived separately in JavaScript:
22
22
23
23
<DiagramGroup>
24
24
@@ -36,7 +36,7 @@ JavaScript
36
36
37
37
</DiagramGroup>
38
38
39
-
Lakini kadri Wavuti ilivyozidi kuwa na mwingiliano, mantiki ilizidi kuamua maudhui. JavaScript ilikuwa msimamizi wa HTML! Ndiyo maana **katika React, mantiki ya ku-render na markup hukaa pamoja mahali pamoja—components.**
39
+
But as the Web became more interactive, logic increasingly determined content. JavaScript was in charge of the HTML! This is why **in React, rendering logic and markup live together in the same place—components.**
40
40
41
41
<DiagramGroup>
42
42
@@ -54,19 +54,19 @@ Lakini kadri Wavuti ilivyozidi kuwa na mwingiliano, mantiki ilizidi kuamua maudh
54
54
55
55
</DiagramGroup>
56
56
57
-
Kuweka mantiki ya ku-render ya kitufe na markup yake pamoja kunahakikisha vinabaki kupatana kila wakati unapofanya mabadiliko. Kinyume chake, mambo yasiyohusiana, kama vile markup ya kitufe na markup ya sidebar, hutengwa mbali na kila kimoja, jambo linalofanya kuwa salama zaidi kubadilisha chochote kati yao peke yake.
57
+
Keeping a button's rendering logic and markup together ensures that they stay in sync with each other on every edit. Conversely, details that are unrelated, such as the button's markup and a sidebar's markup, are isolated from each other, making it safer to change either of them on their own.
58
58
59
-
Kila React component ni function ya JavaScript ambayo huenda ikawa na markup fulani ambayo React huii-render kwenye kivinjari. Components za React hutumia kiendelezi cha sintaksia kiitwacho JSX kuwakilisha markup hiyo. JSX inafanana sana na HTML, lakini ni kali kidogo zaidi na inaweza kuonyesha taarifa zinazobadilika. Njia bora ya kuelewa hili ni kubadilisha markup fulani ya HTML kuwa markup ya JSX.
59
+
Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information. The best way to understand this is to convert some HTML markup to JSX markup.
60
60
61
61
<Note>
62
62
63
-
JSX na React ni vitu viwili tofauti. Mara nyingi hutumika pamoja, lakini *unaweza*[kuvitumia kwa kujitegemea](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#whats-a-jsx-transform)kila kimoja. JSX ni kiendelezi cha sintaksia, ilhali React ni maktaba ya JavaScript.
63
+
JSX and React are two separate things. They're often used together, but you *can*[use them independently](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#whats-a-jsx-transform)of each other. JSX is a syntax extension, while React is a JavaScript library.
64
64
65
65
</Note>
66
66
67
-
## Kubadilisha HTML kuwa JSX {/*converting-html-to-jsx*/}
67
+
## Converting HTML to JSX {/*converting-html-to-jsx*/}
68
68
69
-
Tuseme una HTML fulani (halali kabisa):
69
+
Suppose that you have some (perfectly valid) HTML:
70
70
71
71
```html
72
72
<h1>Hedy Lamarr's Todos</h1>
@@ -82,7 +82,7 @@ Tuseme una HTML fulani (halali kabisa):
82
82
</ul>
83
83
```
84
84
85
-
Na unataka kuiweka ndani ya component yako:
85
+
And you want to put it into your component:
86
86
87
87
```js
88
88
exportdefaultfunctionTodoList() {
@@ -92,15 +92,15 @@ export default function TodoList() {
92
92
}
93
93
```
94
94
95
-
Ukiinakili na kuibandika kama ilivyo, haitafanya kazi:
95
+
If you copy and paste it as is, it will not work:
96
96
97
97
98
98
<Sandpack>
99
99
100
100
```js
101
101
exportdefaultfunctionTodoList() {
102
102
return (
103
-
//Hii haifanyi kazi vizuri!
103
+
//This doesn't quite work!
104
104
<h1>Hedy Lamarr's Todos</h1>
105
105
<img
106
106
src="https://i.imgur.com/yXOvdOSs.jpg"
@@ -122,21 +122,21 @@ img { height: 90px }
122
122
123
123
</Sandpack>
124
124
125
-
Hii ni kwa sababu JSX ni kali zaidi na ina kanuni chache zaidi kuliko HTML! Ukisoma ujumbe wa hitilafu ulio hapo juu, utakuongoza kurekebisha markup, au unaweza kufuata mwongozo ulio hapa chini.
125
+
This is because JSX is stricter and has a few more rules than HTML! If you read the error messages above, they'll guide you to fix the markup, or you can follow the guide below.
126
126
127
127
<Note>
128
128
129
-
Mara nyingi, ujumbe wa hitilafu wa React unaoonekana kwenye skrini utakusaidia kupata mahali tatizo lilipo. Uupe usomaji kama umekwama!
129
+
Most of the time, React's on-screen error messages will help you find where the problem is. Give them a read if you get stuck!
130
130
131
131
</Note>
132
132
133
-
## Kanuni za JSX {/*the-rules-of-jsx*/}
133
+
## The Rules of JSX {/*the-rules-of-jsx*/}
134
134
135
-
### 1. Rudisha elementi moja ya mzizi {/*1-return-a-single-root-element*/}
135
+
### 1. Return a single root element {/*1-return-a-single-root-element*/}
136
136
137
-
Ili kurudisha elementi nyingi kutoka kwenye component, **zifunge kwa tagi moja ya mzazi.**
137
+
To return multiple elements from a component, **wrap them with a single parent tag.**
138
138
139
-
Kwa mfano, unaweza kutumia `<div>`:
139
+
For example, you can use a `<div>`:
140
140
141
141
```js {1,11}
142
142
<div>
@@ -153,7 +153,7 @@ Kwa mfano, unaweza kutumia `<div>`:
153
153
```
154
154
155
155
156
-
Kama hutaki kuongeza `<div>`ya ziada kwenye markup yako, unaweza kuandika `<>`na`</>`badala yake:
156
+
If you don't want to add an extra `<div>`to your markup, you can write `<>`and`</>`instead:
157
157
158
158
```js {1,11}
159
159
<>
@@ -169,21 +169,21 @@ Kama hutaki kuongeza `<div>` ya ziada kwenye markup yako, unaweza kuandika `<>`
169
169
</>
170
170
```
171
171
172
-
Tagi hii tupu inaitwa *[Fragment.](/reference/react/Fragment)* Fragments zinakuwezesha kuweka vitu katika kundi bila kuacha alama yoyote katika mti wa HTML wa kivinjari.
172
+
This empty tag is called a *[Fragment.](/reference/react/Fragment)* Fragments let you group things without leaving any trace in the browser HTML tree.
173
173
174
174
<DeepDive>
175
175
176
-
#### Kwa nini tagi nyingi za JSX zinahitaji kufungwa? {/*why-do-multiple-jsx-tags-need-to-be-wrapped*/}
176
+
#### Why do multiple JSX tags need to be wrapped? {/*why-do-multiple-jsx-tags-need-to-be-wrapped*/}
177
177
178
-
JSX inafanana na HTML, lakini ndani ya pazia hubadilishwa kuwa objects za kawaida za JavaScript. Huwezi kurudisha objects mbili kutoka kwa function bila kuzifunga ndani ya array (safu). Hii inaeleza kwa nini pia huwezi kurudisha tagi mbili za JSX bila kuzifunga ndani ya tagi nyingine au Fragment.
178
+
JSX looks like HTML, but under the hood it is transformed into plain JavaScript objects. You can't return two objects from a functionwithout wrapping them into an array. This explains why you also can't return two JSX tags without wrapping them into another tag or a Fragment.
179
179
180
180
</DeepDive>
181
181
182
-
### 2. Funga tagi zote {/*2-close-all-the-tags*/}
182
+
### 2. Close all the tags {/*2-close-all-the-tags*/}
183
183
184
-
JSX inahitaji tagi zifungwe waziwazi: tagi zinazojifunga zenyewe kama `<img>` lazima ziwe `<img />`, na tagi zinazofunga kama `<li>oranges` lazima ziandikwe kama `<li>oranges</li>`.
184
+
JSX requires tags to be explicitly closed: self-closing tags like `<img>` must become `<img />`, and wrapping tags like `<li>oranges` must be written as `<li>oranges</li>`.
185
185
186
-
Hivi ndivyo picha ya Hedy Lamarr na vipengele vya orodha vinavyoonekana vikiwa vimefungwa:
186
+
This is how Hedy Lamarr's image and list items look closed:
187
187
188
188
```js {2-6,8-10}
189
189
<>
@@ -200,11 +200,11 @@ Hivi ndivyo picha ya Hedy Lamarr na vipengele vya orodha vinavyoonekana vikiwa v
200
200
</>
201
201
```
202
202
203
-
### 3. camelCase <s>vitu vyote</s> vingi vya vitu! {/*3-camelcase-salls-most-of-the-things*/}
203
+
### 3. camelCase <s>all</s> most of the things! {/*3-camelcase-salls-most-of-the-things*/}
204
204
205
-
JSX hugeuka kuwa JavaScript na sifa zilizoandikwa katika JSX huwa keys za objects za JavaScript. Katika components zako mwenyewe, mara nyingi utataka kusoma sifa hizo ndani ya vigezo. Lakini JavaScript ina vikwazo kwenye majina ya vigezo. Kwa mfano, majina yao hayawezi kuwa na mistari-tandavu au kuwa maneno yaliyohifadhiwa kama `class`.
205
+
JSX turns into JavaScript and attributes written in JSX become keys of JavaScript objects. In your own components, you will often want to read those attributes into variables. But JavaScript has limitations on variable names. For example, their names can't contain dashes or be reserved words like `class`.
206
206
207
-
Ndiyo maana, katika React, sifa nyingi za HTML na SVG huandikwa kwa camelCase. Kwa mfano, badala ya `stroke-width` unatumia `strokeWidth`. Kwa kuwa `class` ni neno lililohifadhiwa, katika React unaandika `className` badala yake, lililopewa jina kutokana na [sifa inayolingana ya DOM](https://developer.mozilla.org/en-US/docs/Web/API/Element/className):
207
+
This is why, in React, many HTML and SVG attributes are written in camelCase. For example, instead of `stroke-width` you use `strokeWidth`. Since `class` is a reserved word, in React you write `className` instead, named after the [corresponding DOM property](https://developer.mozilla.org/en-US/docs/Web/API/Element/className):
208
208
209
209
```js {4}
210
210
<img
@@ -214,19 +214,19 @@ Ndiyo maana, katika React, sifa nyingi za HTML na SVG huandikwa kwa camelCase. K
214
214
/>
215
215
```
216
216
217
-
Unaweza [kuzipata sifa hizi zote katika orodha ya props za DOM components.](/reference/react-dom/components/common) Ukikosea moja, usijali—React itachapisha ujumbe wenye marekebisho yanayowezekana kwenye [console ya kivinjari.](https://developer.mozilla.org/docs/Tools/Browser_Console)
217
+
Youcan [findalltheseattributesinthelistofDOMcomponentprops.](/reference/react-dom/components/common) Ifyougetonewrong, don't worry—React will print a message with a possible correction to the [browser console.](https://developer.mozilla.org/docs/Tools/Browser_Console)
218
218
219
219
<Pitfall>
220
220
221
-
Kwa sababu za kihistoria, sifa za [`aria-*`](https://developer.mozilla.org/docs/Web/Accessibility/ARIA) na [`data-*`](https://developer.mozilla.org/docs/Learn/HTML/Howto/Use_data_attributes) huandikwa kama zilivyo katika HTML kwa mistari-tandavu.
221
+
For historical reasons, [`aria-*`](https://developer.mozilla.org/docs/Web/Accessibility/ARIA) and [`data-*`](https://developer.mozilla.org/docs/Learn/HTML/Howto/Use_data_attributes) attributes are written as in HTML with dashes.
222
222
223
223
</Pitfall>
224
224
225
-
### Kidokezo cha kitaalamu: Tumia Kigeuzi cha JSX {/*pro-tip-use-a-jsx-converter*/}
225
+
### Pro-tip: Use a JSX Converter {/*pro-tip-use-a-jsx-converter*/}
226
226
227
-
Kubadilisha sifa hizi zote katika markup iliyopo kunaweza kuchosha! Tunapendekeza kutumia [kigeuzi](https://transform.tools/html-to-jsx) kutafsiri HTML na SVG yako iliyopo kuwa JSX. Vigeuzi vina manufaa makubwa katika matumizi halisi, lakini bado ni muhimu kuelewa kinachoendelea ili uweze kuandika JSX kwa raha mwenyewe.
227
+
Converting all these attributes in existing markup can be tedious! We recommend using a [converter](https://transform.tools/html-to-jsx) to translate your existing HTML and SVG to JSX. Converters are very useful in practice, but it'sstillworthunderstandingwhatisgoingonsothatyoucancomfortablywriteJSXonyourown.
228
228
229
-
Hapa kuna matokeo yako ya mwisho:
229
+
Hereisyourfinalresult:
230
230
231
231
<Sandpack>
232
232
@@ -258,21 +258,21 @@ img { height: 90px }
258
258
259
259
<Recap>
260
260
261
-
Sasa unajua kwa nini JSX ipo na jinsi ya kuitumia katika components:
261
+
NowyouknowwhyJSXexistsandhowtouseitincomponents:
262
262
263
-
*Components za React huweka mantiki ya ku-render pamoja na markup kwa sababu vinahusiana.
264
-
* JSX inafanana na HTML, kwa tofauti chache. Unaweza kutumia [kigeuzi](https://transform.tools/html-to-jsx)kama unahitaji.
265
-
*Ujumbe wa hitilafu mara nyingi utakuelekeza katika njia sahihi ya kurekebisha markup yako.
0 commit comments