Skip to content

Commit 7f42fe1

Browse files
authored
Merge pull request #50 from ahmedkaba/typechecking-with-proptypes
Translation of Typechecking With PropTypes
2 parents 1a9cf68 + cf523d7 commit 7f42fe1

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed
+41-41
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
id: typechecking-with-proptypes
3-
title: Typechecking With PropTypes
3+
title: PropTypes ile Tip Kontrolü
44
permalink: docs/typechecking-with-proptypes.html
55
redirect_from:
66
- "docs/react-api.html#typechecking-with-proptypes"
77
---
88

9-
> Note:
9+
> Not:
1010
>
11-
> `React.PropTypes` has moved into a different package since React v15.5. Please use [the `prop-types` library instead](https://www.npmjs.com/package/prop-types).
11+
> `React.PropTypes` React v15.5'ten bu yana farklı bir pakete taşındı. Lütfen bunun yerine [`prop-types` kütüphanesini kullanın](https://www.npmjs.com/package/prop-types).
1212
>
13-
>We provide [a codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes) to automate the conversion.
13+
> Dönüştürme işlemini otomatikleştirmek için [bir codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes)'i sunuyoruz.
1414
15-
As your app grows, you can catch a lot of bugs with typechecking. For some applications, you can use JavaScript extensions like [Flow](https://flow.org/) or [TypeScript](https://www.typescriptlang.org/) to typecheck your whole application. But even if you don't use those, React has some built-in typechecking abilities. To run typechecking on the props for a component, you can assign the special `propTypes` property:
15+
Uygulamanız büyüdükçe, tip kontrolü ile birçok hata yakalayabilirsiniz. Bazı uygulamalarda, tüm uygulamanız üzerinde tip kontrolü yapmak için [Flow](https://flow.org/) veya [TypeScript](https://www.typescriptlang.org/) gibi JavaScript uzantılarını kullanabilirsiniz. Ama bunları kullanmasanız bile, React bazı yerleşik tip kontrolü yeteneklerine sahiptir. Bir bileşenin prop'ları üzerinde tip kontrolü yapmak için, özel `propTypes` niteliğini atayabilirsiniz:
1616

1717
```javascript
1818
import PropTypes from 'prop-types';
@@ -30,18 +30,18 @@ Greeting.propTypes = {
3030
};
3131
```
3232

33-
`PropTypes` exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're using `PropTypes.string`. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. For performance reasons, `propTypes` is only checked in development mode.
33+
`PropTypes` alınan verilerin geçerli olduğundan emin olmak için kullanılabilecek bir dizi doğrulayıcı verir. Bu örnekte, `PropTypes.string`'i kullanıyoruz. Bir prop için geçersiz bir değer sağlandığında, JavaScript konsolunda bir uyarı gösterilecektir. Performans nedeniyle, `propTypes` sadece geliştirme modunda kontrol edilir.
3434

3535
### PropTypes {#proptypes}
3636

37-
Here is an example documenting the different validators provided:
37+
İşte sağlanan çeşitli doğrulayıcıları gösteren bir örnek:
3838

3939
```javascript
4040
import PropTypes from 'prop-types';
4141

4242
MyComponent.propTypes = {
43-
// You can declare that a prop is a specific JS type. By default, these
44-
// are all optional.
43+
// Bir prop'un belirli bir JS türü olduğunu belirtebilirsiniz.
44+
// Varsayılan olarak, bunların hepsi isteğe bağlıdır.
4545
optionalArray: PropTypes.array,
4646
optionalBool: PropTypes.bool,
4747
optionalFunc: PropTypes.func,
@@ -50,50 +50,50 @@ MyComponent.propTypes = {
5050
optionalString: PropTypes.string,
5151
optionalSymbol: PropTypes.symbol,
5252

53-
// Anything that can be rendered: numbers, strings, elements or an array
54-
// (or fragment) containing these types.
53+
// Render edilebilecek her şey: sayılar, dizeler, elemanlar veya bir dizi
54+
// (veya fragment) bu türleri içeren.
5555
optionalNode: PropTypes.node,
5656

57-
// A React element.
57+
// React elemanı.
5858
optionalElement: PropTypes.element,
5959

60-
// You can also declare that a prop is an instance of a class. This uses
61-
// JS's instanceof operator.
60+
// Bir prop'un sınıf nesnesi olduğunu da belirtebilirsiniz.
61+
// Bu JS'in instanceof operatörünü kullanır.
6262
optionalMessage: PropTypes.instanceOf(Message),
6363

64-
// You can ensure that your prop is limited to specific values by treating
65-
// it as an enum.
66-
optionalEnum: PropTypes.oneOf(['News', 'Photos']),
64+
// Bir prop'un enum olarak değerlendirilerek
65+
// belirli değerlerle sınırlı olmasını sağlayabilirsiniz.
66+
optionalEnum: PropTypes.oneOf(['Haberler', 'Fotoğraflar']),
6767

68-
// An object that could be one of many types
68+
// Birçok türden birinin olabileceği bir nesne
6969
optionalUnion: PropTypes.oneOfType([
7070
PropTypes.string,
7171
PropTypes.number,
7272
PropTypes.instanceOf(Message)
7373
]),
7474

75-
// An array of a certain type
75+
// Belirli bir türde bir dizi
7676
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
7777

78-
// An object with property values of a certain type
78+
// Belirli bir türde özellik değerlerine sahip bir nesne
7979
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
8080

81-
// An object taking on a particular shape
81+
// Belirli bir şekildeki nesne
8282
optionalObjectWithShape: PropTypes.shape({
8383
color: PropTypes.string,
8484
fontSize: PropTypes.number
8585
}),
8686

87-
// You can chain any of the above with `isRequired` to make sure a warning
88-
// is shown if the prop isn't provided.
87+
// Prop'un sağlanmadığı durumlarda bir uyarının gösterildiğinden emin olmak için,
88+
// yukarıdakilerden herhangi birini `isRequired` ile zincirleyebilirsiniz.
8989
requiredFunc: PropTypes.func.isRequired,
9090

91-
// A value of any data type
91+
// Herhangi bir veri türünün değeri
9292
requiredAny: PropTypes.any.isRequired,
9393

94-
// You can also specify a custom validator. It should return an Error
95-
// object if the validation fails. Don't `console.warn` or throw, as this
96-
// won't work inside `oneOfType`.
94+
// Özel bir doğrulayıcı da belirtebilirsiniz.
95+
// Doğrulama başarısız olursa bir Error nesnesi döndürmelidir.
96+
// `console.warn` veya `throw` kullanmayın, çünkü bu `oneOfType` içinde çalışmayacaktır.
9797
customProp: function(props, propName, componentName) {
9898
if (!/matchme/.test(props[propName])) {
9999
return new Error(
@@ -103,11 +103,11 @@ MyComponent.propTypes = {
103103
}
104104
},
105105

106-
// You can also supply a custom validator to `arrayOf` and `objectOf`.
107-
// It should return an Error object if the validation fails. The validator
108-
// will be called for each key in the array or object. The first two
109-
// arguments of the validator are the array or object itself, and the
110-
// current item's key.
106+
// Ayrıca `arrayOf` ve `objectOf`'lara özel bir doğrulayıcı da belirtebilirsiniz.
107+
// Doğrulama başarısız olursa bir Error nesnesi döndürmelidir.
108+
// Doğrulayıcı, dizideki veya nesnedeki her anahtar için çağrılacaktır.
109+
// Doğrulayıcının ilk iki argümanı dizi veya nesnenin kendisi
110+
// ve geçerli öğenin anahtarıdır.
111111
customArrayProp: PropTypes.arrayOf(function(propValue, key, componentName, location, propFullName) {
112112
if (!/matchme/.test(propValue[key])) {
113113
return new Error(
@@ -119,16 +119,16 @@ MyComponent.propTypes = {
119119
};
120120
```
121121

122-
### Requiring Single Child {#requiring-single-child}
122+
### Tek Alt Eleman Gerektirmek {#requiring-single-child}
123123

124-
With `PropTypes.element` you can specify that only a single child can be passed to a component as children.
124+
`PropTypes.element` ile, yalnızca tek bir elemanın bir bileşene alt eleman olarak geçeceğini belirtebilirsiniz.
125125

126126
```javascript
127127
import PropTypes from 'prop-types';
128128

129129
class MyComponent extends React.Component {
130130
render() {
131-
// This must be exactly one element or it will warn.
131+
// Bu kesinlikle tek bir eleman olmalı; aksi takdirde uyarı verecektir.
132132
const children = this.props.children;
133133
return (
134134
<div>
@@ -143,9 +143,9 @@ MyComponent.propTypes = {
143143
};
144144
```
145145

146-
### Default Prop Values {#default-prop-values}
146+
### Varsayılan Prop Değerleri {#default-prop-values}
147147

148-
You can define default values for your `props` by assigning to the special `defaultProps` property:
148+
Özel `defaultProps` niteliğine atama yaparak, `prop`'larınız için varsayılan değerleri tanımlayabilirsiniz:
149149

150150
```javascript
151151
class Greeting extends React.Component {
@@ -156,19 +156,19 @@ class Greeting extends React.Component {
156156
}
157157
}
158158

159-
// Specifies the default values for props:
159+
// Prop'lar için varsayılan değerleri belirtir:
160160
Greeting.defaultProps = {
161161
name: 'Stranger'
162162
};
163163

164-
// Renders "Hello, Stranger":
164+
// "Hello, Stranger" yazısını çıktılar:
165165
ReactDOM.render(
166166
<Greeting />,
167167
document.getElementById('example')
168168
);
169169
```
170170

171-
If you are using a Babel transform like [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) , you can also declare `defaultProps` as static property within a React component class. This syntax has not yet been finalized though and will require a compilation step to work within a browser. For more information, see the [class fields proposal](https://github.com/tc39/proposal-class-fields).
171+
Eğer [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) gibi bir Babel dönüşümü kullanıyorsanız, `defaultProps`'u bir React bileşen sınıfında statik özellik olarak da tanımlayabilirsiniz. Bu sözdizimi henüz tamamlanmadı ve tarayıcıda çalışabilmesi için bir derleme adımı gerektirecektir. Daha fazla bilgi için, [sınıf alanları önergesi](https://github.com/tc39/proposal-class-fields)'ne göz atabilirsiniz.
172172

173173
```javascript
174174
class Greeting extends React.Component {
@@ -184,4 +184,4 @@ class Greeting extends React.Component {
184184
}
185185
```
186186

187-
The `defaultProps` will be used to ensure that `this.props.name` will have a value if it was not specified by the parent component. The `propTypes` typechecking happens after `defaultProps` are resolved, so typechecking will also apply to the `defaultProps`.
187+
`this.props.name`'in üst bileşen tarafından belirtilen bir değerinin olmadığı durumlarda, varsayılan bir değere sahip olmasını sağlamak için `defaultProps` kullanılır. `propTypes` tip kontrolü `defaultProps` çözümlendikten sonra gerçekleşir, bu nedenle tip kontrolü `defaultProps` için de geçerli olacaktır.

0 commit comments

Comments
 (0)