└── README.md
/README.md:
--------------------------------------------------------------------------------
1 | # Airbnb React/JSX Stil Rehberi
2 |
3 | **(Turkish Translation of [Airbnb React/JSX Style Guide](https://github.com/airbnb/javascript/tree/master/react)**
4 |
5 | *React and JSX konularına oldukça makul bir yaklaşım*
6 |
7 | ## içindeki
8 |
9 | 1. [Temel Kurallar](#temel-kurallar)
10 | 1. [Class vs `React.createClass` vs stateless](#class-vs-reactcreateclass-vs-stateless)
11 | 1. [Mixinler](#mixins)
12 | 1. [Isimlendirme](#isimlendirme)
13 | 1. [Deklarasyon](#deklarasyon)
14 | 1. [Hizalama](#hizalama)
15 | 1. [Tırnaklar](#tırnaklar)
16 | 1. [Boşluk Kullanımı](#boşluk-kullanımı)
17 | 1. [Proplar](#proplar)
18 | 1. [Refler](#refler)
19 | 1. [Parantezler](#parantezler)
20 | 1. [Taglar](#tagler)
21 | 1. [Metodlar](#metodlar)
22 | 1. [Sıralama](#sıralama)
23 | 1. [`isMounted`](#ismounted)
24 |
25 | ## Temel Kurallar
26 |
27 | - Her bir dosyada sadece bir adet React Componenti barındırın.
28 | - Ama, birden fazla [Stateless ya da Pure Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) aynı dosyada kullanılabilir. eslint: [`react/no-multi-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md#ignorestateless).
29 | - Daima JSX i kullanın.
30 | - Uygulamayı JSX olmayan bir dosyadan başlatmadığınız sürece `React.createElement` i kullanmayın.
31 |
32 | ## Class vs `React.createClass` vs stateless
33 | - Eğer dahili olarak state ve / veya ref ler varsa, `React.createClass` yerine `class extends React.Component` kullanmayı tercih edin. eslint: [`react/prefer-es6-class`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md) [`react/prefer-stateless-function`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md)
34 |
35 | ```jsx
36 | // kötü
37 | const Listing = React.createClass({
38 | // ...
39 | render() {
40 | return
{this.state.hello}
;
41 | }
42 | });
43 |
44 | // iyi
45 | class Listing extends React.Component {
46 | // ...
47 | render() {
48 | return {this.state.hello}
;
49 | }
50 | }
51 | ```
52 |
53 | Ve eğer state ya da ref leriniz yoksa, class lar içinde normal fonksiyonları (arrow fonksiyonları değil) tercih edin:
54 |
55 | ```jsx
56 | // kötü
57 | class Listing extends React.Component {
58 | render() {
59 | return {this.props.hello}
;
60 | }
61 | }
62 |
63 | // kötü (Fonksiyon ismi çıkarımına güvenmek cesaret kırıcıdır.)
64 | const Listing = ({ hello }) => (
65 | {hello}
66 | );
67 |
68 | // iyi
69 | function Listing({ hello }) {
70 | return {hello}
;
71 | }
72 | ```
73 |
74 | ## Mixins
75 |
76 | - [Mixinleri kullanmayın](https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html).
77 |
78 | > Niye? Mixinler örtülü bağımlılıkları ortaya çıkarır, isim çatışmalarına neden olur ve snowballing karmaşıklığına neden olur. Mixinlerin kullanılmak istendiği bir çok durum, bileşenleri, daha üst düzey bileşenleri veya yardımcı modülleri kullanarak daha iyi yollarla başarılabilir.
79 |
80 | ## isimlendirme
81 |
82 | - **Dosya Uzantıları**: React Bileşenleri için `.jsx` uzantısını kullanın.
83 | - **Dosya İsimleri**: Dosya isimleri için PascalCase yöntemini kullanın. Mesela, `ReservationCard.jsx`.
84 | - **Reference İsimlendirmesi**: React Bileşenleri için PascalCase ve onların örnekleri için camelCase yöntemini kullanın. eslint: [`react/jsx-pascal-case`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md)
85 |
86 | ```jsx
87 | // kötü
88 | import reservationCard from './ReservationCard';
89 |
90 | // iyi
91 | import ReservationCard from './ReservationCard';
92 |
93 | // kötü
94 | const ReservationItem = ;
95 |
96 | // iyi
97 | const reservationItem = ;
98 | ```
99 |
100 | - **Bileşen İsimlendirmesi**: Bileşen ismi olarak dosya adını kullanın. Örneğin, `ReservationCard.jsx` dosyası `ReservationCard` adında bir bileşeni içermelidir. Ancak, bir klasörün kök bileşeni için; dosya ismi olarak `index.jsx` ve bileşen ismi olarak da klasörün ismini kullanın:
101 |
102 | ```jsx
103 | // kötü
104 | import Footer from './Footer/Footer';
105 |
106 | // iyi
107 | import Footer from './Footer/index';
108 |
109 | // iyi
110 | import Footer from './Footer';
111 | ```
112 | - **Üst-Sıralı Bileşen İsimlendirmesi**: Oluşturulan bileşen üzerinde `displayName` olarak Üst-Sıralı Bileşen ismi ve aktarılan bileşenin isminden oluşan bir karma isim kullanın. Örneğin, Üst-Sıralı bileşen üyesi olan `WithFoo ()` öğesi, `Bar` adındakı bir bileşen tarafından iletildiğinde, `displayName` i `withFoo(Bar)` olan bir bileşen üretmelidir.
113 |
114 | > Neden? Bir Bileşenin `displayName` i, geliştirici araçlarında veya hata mesajlarında kullanılabilir; ve bu ilişkiyi açıkça ifade eden bir değere sahip olması, insanların neler olduğunu anlamasına yardımcı olur.
115 |
116 | ```jsx
117 | // kötü
118 | export default function withFoo(WrappedComponent) {
119 | return function WithFoo(props) {
120 | return ;
121 | }
122 | }
123 |
124 | // iyi
125 | export default function withFoo(WrappedComponent) {
126 | function WithFoo(props) {
127 | return ;
128 | }
129 |
130 | const wrappedComponentName = WrappedComponent.displayName
131 | || WrappedComponent.name
132 | || 'Component';
133 |
134 | WithFoo.displayName = `withFoo(${wrappedComponentName})`;
135 | return WithFoo;
136 | }
137 | ```
138 |
139 | - **Propların İsimlendirmesi**: DOM Bileşenlerine ait isimleri başka amaçlar için kullanmaktan kaçının.
140 |
141 | > Neden? İnsanlar `style` ve `className` gibi proplarin tek belirgin bir anlama gelmesini bekler. Bu API yi uygulamanızın bir alt kümesi için değiştirmek kodu daha az okunabilir ve daha az sürdürülebilir hale getirir, ve buglara sebep olabilir.
142 |
143 | ```jsx
144 | // kötü
145 |
146 |
147 | // iyi
148 |
149 | ```
150 |
151 | ## Deklarasyon
152 |
153 | - Bileşenleri isimlendirmek için `displayName` kullanmayın. Onun yerine bileşeni referansa göre isimlendirin.
154 |
155 | ```jsx
156 | // kötü
157 | export default React.createClass({
158 | displayName: 'ReservationCard',
159 | // stuff goes here
160 | });
161 |
162 | // iyi
163 | export default class ReservationCard extends React.Component {
164 | }
165 | ```
166 |
167 | ## Hizalama
168 |
169 | - JSX sözdizimi için bu hizalama stillerini takip edin: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md) [`react/jsx-closing-tag-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md)
170 |
171 | ```jsx
172 | // kötü
173 |
175 |
176 | // iyi
177 |
181 |
182 | // Eğer proplar bir satıra sığıyorsa aynı satırda tutun.
183 |
184 |
185 | // çocuklar normal olarak hizalanır.
186 |
190 |
191 |
192 | ```
193 |
194 | ## Tırnaklar
195 |
196 | - JSX nitelikleri için daima çift tırnak (`"`), ama diğer bütün JS için tek tırnak (`'`) kullanın. eslint: [`jsx-quotes`](http://eslint.org/docs/rules/jsx-quotes)
197 |
198 | > Neden? Normal HTML nitelikleri de tek tırnak yerine çift tırnak kullanır, JSX nitelikleri de bu düzeni yansıtır.
199 |
200 | ```jsx
201 | // kötü
202 |
203 |
204 | // iyi
205 |
206 |
207 | // kötü
208 |
209 |
210 | // iyi
211 |
212 | ```
213 |
214 | ## Boşluk Kullanımı
215 |
216 | - Kendi kendine kapanan taglar için daima tek boşluk kullanın. eslint: [`no-multi-spaces`](http://eslint.org/docs/rules/no-multi-spaces), [`react/jsx-tag-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md)
217 |
218 | ```jsx
219 | // kötü
220 |
221 |
222 | // çok kötü
223 |
224 |
225 | // kötü
226 |
228 |
229 | // good
230 |
231 | ```
232 |
233 | - JSX süslü parantezlerini boşlukla şişirmeyin. eslint: [`react/jsx-curly-spacing`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md)
234 |
235 | ```jsx
236 | // kötü
237 |
238 |
239 | // iyi
240 |
241 | ```
242 |
243 | ## Proplar
244 |
245 | - Prop isimleri için daima camelCase kullanın.
246 |
247 | ```jsx
248 | // kötü
249 |
253 |
254 | // iyi
255 |
259 | ```
260 |
261 | - Açıkça `true` olarak belirtildiyse propun değerini atlayın. eslint: [`react/jsx-boolean-value`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md)
262 |
263 | ```jsx
264 | // kötü
265 |
268 |
269 | // iyi
270 |
273 |
274 | // iyi
275 |
276 | ```
277 |
278 | - `
` etiketlerine daima bir `alt` özelliği ekleyin. Eğer resim sunumsal ise, `alt` boş bir dize olabilir veya `
` etiketinde `
284 |
285 | // iyi
286 |
287 |
288 | // iyi
289 |
290 |
291 | // iyi
292 |
293 | ```
294 |
295 | - `
` etiketinin `alt` özelliğinde "image", "photo", ya da "picture" gibi kelimeler kullanmayın. eslint: [`jsx-a11y/img-redundant-alt`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/img-redundant-alt.md)
296 |
297 | > Neden? Ekran okuyucuları zaten `img` elemanlarını resim olarak bildirdikleri için bu bilgiyi alt metne eklemenize gerek yoktur.
298 |
299 | ```jsx
300 | // kötü
301 |
302 |
303 | // iyi
304 |
305 | ```
306 |
307 | - Yalnızca geçerli, soyut olmayan [ARIA roles](https://www.w3.org/TR/wai-aria-1.1/#role_definitions) kullanın. eslint: [`jsx-a11y/aria-role`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/aria-role.md)
308 |
309 | ```jsx
310 | // kötü - bir ARIA role değil
311 |
312 |
313 | // kötü - soyut ARIA role
314 |
315 |
316 | // iyi
317 |
318 | ```
319 |
320 | - Elemanlarde `accessKey` kullanmayın. eslint: [`jsx-a11y/no-access-key`](https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-access-key.md)
321 |
322 | > Neden? Ekran okuyucu kullanan insanlar tarafından kullanılan klavye komutları ve klavye kısayolları ile klavyeler arasındaki tutarsızlıkar erişilebilirliği zorlaştırmaktadır.
323 |
324 | ```jsx
325 | // bad
326 |
327 |
328 | // good
329 |
330 | ```
331 |
332 | - `key` özelliği için dizinin index değerini kullanmaktan kaçının; benzersiz bir ID tercih edin. ([why?](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318))
333 |
334 | ```jsx
335 | // kötü
336 | {todos.map((todo, index) =>
337 |
341 | )}
342 |
343 | // iyi
344 | {todos.map(todo => (
345 |
349 | ))}
350 | ```
351 |
352 | - Always define explicit defaultProps for all non-required props.
353 |
354 | > Why? propTypes are a form of documentation, and providing defaultProps means the reader of your code doesn’t have to assume as much. In addition, it can mean that your code can omit certain type checks.
355 |
356 | ```jsx
357 | // bad
358 | function SFC({ foo, bar, children }) {
359 | return {foo}{bar}{children}
;
360 | }
361 | SFC.propTypes = {
362 | foo: PropTypes.number.isRequired,
363 | bar: PropTypes.string,
364 | children: PropTypes.node,
365 | };
366 |
367 | // good
368 | function SFC({ foo, bar, children }) {
369 | return {foo}{bar}{children}
;
370 | }
371 | SFC.propTypes = {
372 | foo: PropTypes.number.isRequired,
373 | bar: PropTypes.string,
374 | children: PropTypes.node,
375 | };
376 | SFC.defaultProps = {
377 | bar: '',
378 | children: null,
379 | };
380 | ```
381 |
382 | ## Refler
383 |
384 | - ref değeri için her zaman callback kullanın. eslint: [`react/no-string-refs`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md)
385 |
386 | ```jsx
387 | // kötü
388 |
391 |
392 | // iyi
393 | { this.myRef = ref; }}
395 | />
396 | ```
397 |
398 | ## Parantezler
399 |
400 | - JSX etiketleri bir satırdan fazla olursa parantezler kullanın. eslint: [`react/jsx-wrap-multilines`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md)
401 |
402 | ```jsx
403 | // kötü
404 | render() {
405 | return
406 |
407 | ;
408 | }
409 |
410 | // iyi
411 | render() {
412 | return (
413 |
414 |
415 |
416 | );
417 | }
418 |
419 | // iyi, eğer tek satırsa
420 | render() {
421 | const body = hello
;
422 | return {body};
423 | }
424 | ```
425 |
426 | ## Taglar
427 |
428 | - Hiçbir çocuğu olmayan etiketleri her zaman kendi kendine kapatın. eslint: [`react/self-closing-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md)
429 |
430 | ```jsx
431 | // kötü
432 |
433 |
434 | // iyi
435 |
436 | ```
437 |
438 | - Eğer bileşeninizin birden çok satırdan oluşan özellikleri varsa, bileşeni yeni bir satırda kapatın. eslint: [`react/jsx-closing-bracket-location`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md)
439 |
440 | ```jsx
441 | // kötü
442 |
445 |
446 | // iyi
447 |
451 | ```
452 |
453 | ## Metodlar
454 |
455 | - Yerel değişkenleri kapatmak için ok fonksiyonları kullanın.
456 |
457 | ```jsx
458 | function ItemList(props) {
459 | return (
460 |
461 | {props.items.map((item, index) => (
462 | - doSomethingWith(item.name, index)}
465 | />
466 | ))}
467 |
468 | );
469 | }
470 | ```
471 |
472 | - Render metodunda kullanılacak olay yöneticilerini constructor metodunda bağlayın. eslint: [`react/jsx-no-bind`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md)
473 |
474 | > Neden? Render metodunda yer alan bir bağlama çağrısı her render işleminde tamamen yeni bir fonksiyon yaratır.
475 |
476 | ```jsx
477 | // kötü
478 | class extends React.Component {
479 | onClickDiv() {
480 | // bişeyler yap
481 | }
482 |
483 | render() {
484 | return ;
485 | }
486 | }
487 |
488 | // iyi
489 | class extends React.Component {
490 | constructor(props) {
491 | super(props);
492 |
493 | this.onClickDiv = this.onClickDiv.bind(this);
494 | }
495 |
496 | onClickDiv() {
497 | // bişeyler yap
498 | }
499 |
500 | render() {
501 | return ;
502 | }
503 | }
504 | ```
505 |
506 | - React bileşeninin dahili metodları için alt çizgi önekini kullanmayın.
507 | > Neden? Alt çizgi önekleri gizliliği belirtmek için diğer dillerde bir kural olarak bazen kullanılır. Fakat, bu dillerin aksine, JavaScript'de gizlilik için doğal bir destek yok, her şey açıktır. Niyetlerinize bakılmaksızın, property lere alt çizgi önekleri eklemek onları aslında gizli kılmaz ve herhangi bir property (alt çizgi öneki içeren veya içermeyen) herkese açık olarak değerlendirilmelidir. Daha detaylı bir tartışma için [#1024](https://github.com/airbnb/javascript/issues/1024) ve [#490](https://github.com/airbnb/javascript/issues/490) sorun sayfalarına göz atın.
508 |
509 | ```jsx
510 | // kötü
511 | React.createClass({
512 | _onClickSubmit() {
513 | // bişeyler yap
514 | },
515 |
516 | // diğer şeyler
517 | });
518 |
519 | // iyi
520 | class extends React.Component {
521 | onClickSubmit() {
522 | // bişeyler yap
523 | }
524 |
525 | // diğer şeyler
526 | }
527 | ```
528 |
529 | - `render` metodunda bir değer döndürdüğünüze emin olun. eslint: [`react/require-render-return`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md)
530 |
531 | ```jsx
532 | // kötü
533 | render() {
534 | ();
535 | }
536 |
537 | // iyi
538 | render() {
539 | return ();
540 | }
541 | ```
542 |
543 | ## Sıralama
544 |
545 | - `class extends React.Component` için sıralama:
546 |
547 | 1. optional `static` methods
548 | 1. `constructor`
549 | 1. `getChildContext`
550 | 1. `componentWillMount`
551 | 1. `componentDidMount`
552 | 1. `componentWillReceiveProps`
553 | 1. `shouldComponentUpdate`
554 | 1. `componentWillUpdate`
555 | 1. `componentDidUpdate`
556 | 1. `componentWillUnmount`
557 | 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
558 | 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
559 | 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
560 | 1. `render`
561 |
562 | - `propTypes`, `defaultProps`, `contextTypes`, vs. nasıl tanımlanır:
563 |
564 | ```jsx
565 | import React from 'react';
566 | import PropTypes from 'prop-types';
567 |
568 | const propTypes = {
569 | id: PropTypes.number.isRequired,
570 | url: PropTypes.string.isRequired,
571 | text: PropTypes.string,
572 | };
573 |
574 | const defaultProps = {
575 | text: 'Hello World',
576 | };
577 |
578 | class Link extends React.Component {
579 | static methodsAreOk() {
580 | return true;
581 | }
582 |
583 | render() {
584 | return {this.props.text};
585 | }
586 | }
587 |
588 | Link.propTypes = propTypes;
589 | Link.defaultProps = defaultProps;
590 |
591 | export default Link;
592 | ```
593 |
594 | - `React.createClass` için sıralama: eslint: [`react/sort-comp`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md)
595 |
596 | 1. `displayName`
597 | 1. `propTypes`
598 | 1. `contextTypes`
599 | 1. `childContextTypes`
600 | 1. `mixins`
601 | 1. `statics`
602 | 1. `defaultProps`
603 | 1. `getDefaultProps`
604 | 1. `getInitialState`
605 | 1. `getChildContext`
606 | 1. `componentWillMount`
607 | 1. `componentDidMount`
608 | 1. `componentWillReceiveProps`
609 | 1. `shouldComponentUpdate`
610 | 1. `componentWillUpdate`
611 | 1. `componentDidUpdate`
612 | 1. `componentWillUnmount`
613 | 1. *clickHandlers or eventHandlers* like `onClickSubmit()` or `onChangeDescription()`
614 | 1. *getter methods for `render`* like `getSelectReason()` or `getFooterContent()`
615 | 1. *optional render methods* like `renderNavigation()` or `renderProfilePicture()`
616 | 1. `render`
617 |
618 | ## `isMounted`
619 |
620 | - `isMounted` kullanmayın. eslint: [`react/no-is-mounted`](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md)
621 |
622 | > Neden? [`isMounted` düzene uygun değildir][anti-pattern], ES6 sınıflarını kullanırken geçerli değildir, ve resmi olarak kaldırılmak için üzeredir.
623 |
624 | [anti-pattern]: https://facebook.github.io/react/blog/2015/12/16/ismounted-antipattern.html
625 |
626 | ## Çeviri
627 |
628 | Bu JSX/React stil rehberi aynı zamanda diğer dillerde de mevcuttur:
629 |
630 | -  **Chinese (Simplified)**: [JasonBoy/javascript](https://github.com/JasonBoy/javascript/tree/master/react)
631 | -  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript/tree/master/react)
632 | -  **Español**: [agrcrobles/javascript](https://github.com/agrcrobles/javascript/tree/master/react)
633 | -  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide/tree/master/react)
634 | -  **Korean**: [apple77y/javascript](https://github.com/apple77y/javascript/tree/master/react)
635 | -  **Polish**: [pietraszekl/javascript](https://github.com/pietraszekl/javascript/tree/master/react)
636 | -  **Portuguese**: [ronal2do/javascript](https://github.com/ronal2do/airbnb-react-styleguide)
637 | -  **Russian**: [leonidlebedev/javascript-airbnb](https://github.com/leonidlebedev/javascript-airbnb/tree/master/react)
638 | -  **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide/tree/master/react)
639 | -  **Turkish**: [alioguzhan/react-style-guide](https://github.com/alioguzhan/react-style-guide)
640 | -  **Ukrainian**: [ivanzusko/javascript](https://github.com/ivanzusko/javascript/tree/master/react)
641 |
642 | **[⬆ back to top](#içindekiler)**
643 |
644 |
--------------------------------------------------------------------------------