Skip to content

Commit f39fd6b

Browse files
sukjaesimsim0709
authored andcommitted
Translated typechecking-with-proptypes page into Korean (#78)
* Translated typechecking-with-proptypes page into Korean * reflected review, changed a few words * Made a correction to reflect request. https://github.com/reactjs/ko.reactjs.org/pull/78\#discussion_r268649283 * Made a correction to reflect request. https://github.com/reactjs/ko.reactjs.org/pull/78\#discussion_r269401480 * Made a correction to reflect request. https://github.com/reactjs/ko.reactjs.org/pull/78\#discussion_r269408822 * Made a correction to reflect request. https://github.com/reactjs/ko.reactjs.org/pull/78\#discussion_r269408957 * Made a correction to reflect request.#78 * Update typechecking-with-proptypes.md
1 parent c0d306d commit f39fd6b

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed
Lines changed: 39 additions & 40 deletions
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와 함께 하는 타입 확인
44
permalink: docs/typechecking-with-proptypes.html
55
redirect_from:
66
- "docs/react-api.html#typechecking-with-proptypes"
77
---
88

9-
> Note:
9+
> 주의
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부터 다른 패키지로 이동하였습니다. 대신 [`prop-types` 라이브러리를](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+
> 우리는 변환을 자동화하기 위하여 [codemod 스크립트를](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes) 제공하고 있습니다.
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+
당신의 앱이 커짐에 따라 타입 확인을 통하면 많은 버그를(bug) 잡을 수 있습니다. 특정 애플리케이션에서는 전체 애플리케이션의 타입 확인을 위하여 [Flow](https://flow.org/) 또는 [TypeScript](https://www.typescriptlang.org/)와 같은 JavaScript 도구(Extensions)를 사용할 수 있습니다. 당신이 이러한 것들을 사용하지 않더라도 React는 내장된 타입 확인 기능들을 가지고 있습니다. 컴포넌트의 props에 타입 확인을 하려면 다음과 같이 특별한 프로퍼티인 propTypes를 선언할 수 있습니다.
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`는 전달받은 데이터의 유효성을 검증하기 위해서 다양한 유효성 검사기(Validator)를 내보냅니다. 아래 예시에서는 `PropTypes.string`을 사용하게 될 것입니다. prop에 유효하지 않은 값이 전달 되었을 때, 경고문이 JavaScript 콘솔을 통해 보일 것입니다. `propTypes`는 성능상의 이유로 개발 모드(Development mode) 에서만 확인될 것입니다.
3434

3535
### PropTypes {#proptypes}
3636

37-
Here is an example documenting the different validators provided:
37+
아래는 제공된 서로 다른 유효성 검사기들을 보여주는 예시입니다.
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+
// prop가 특정 JS 형식임을 선언할 수 있습니다.
44+
// 이것들은 기본적으로 모두 선택 사항입니다.
4545
optionalArray: PropTypes.array,
4646
optionalBool: PropTypes.bool,
4747
optionalFunc: PropTypes.func,
@@ -50,50 +50,49 @@ 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+
// 랜더링 될 수 있는 것들은 다음과 같습니다.
54+
// 숫자(numbers), 문자(strings), 엘리먼트(elements), 또는 이러한 타입들(types)을 포함하고 있는 배열(array) (혹은 배열의 fragment)
5555
optionalNode: PropTypes.node,
5656

57-
// A React element.
57+
// React 엘리먼트.
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+
// prop가 클래스의 인스턴스임을 선언할 수 있습니다.
61+
// 이 경우 JS's instanceof 연산자를 사용합니다.
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.
64+
// 열거형(enum)으로 처리하여 prop가 특정 값들로 제한되도록 할 수 있습니다.
6665
optionalEnum: PropTypes.oneOf(['News', 'Photos']),
6766

68-
// An object that could be one of many types
67+
// 여러 종류중 하나의 종류가 될 수 있는 객체
6968
optionalUnion: PropTypes.oneOfType([
7069
PropTypes.string,
7170
PropTypes.number,
7271
PropTypes.instanceOf(Message)
7372
]),
7473

75-
// An array of a certain type
74+
// 특정 타입의 행렬
7675
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
7776

78-
// An object with property values of a certain type
77+
// 특정 타입의 프로퍼티 값들을 갖는 객체
7978
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
8079

81-
// An object taking on a particular shape
80+
// 특정 형태를 갖는 객체
8281
optionalObjectWithShape: PropTypes.shape({
8382
color: PropTypes.string,
8483
fontSize: PropTypes.number
8584
}),
8685

87-
// You can chain any of the above with `isRequired` to make sure a warning
88-
// is shown if the prop isn't provided.
86+
// 위에 있는 것 모두 `isRequired`와 연결하여 prop가 제공되지 않았을 때
87+
// 경고가 보이도록 할 수 있습니다.
8988
requiredFunc: PropTypes.func.isRequired,
9089

91-
// A value of any data type
90+
// 모든 데이터 타입이 가능한 값
9291
requiredAny: PropTypes.any.isRequired,
9392

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`.
93+
// 사용자 정의 유효성 검사기를 지정할 수도 있습니다.
94+
// 검사 실패 시에는 에러(Error) 객체를 반환해야 합니다.
95+
// `oneOfType`안에서는 작동하지 않으므로 `console.warn` 혹은 throw 하지 마세요.
9796
customProp: function(props, propName, componentName) {
9897
if (!/matchme/.test(props[propName])) {
9998
return new Error(
@@ -103,11 +102,11 @@ MyComponent.propTypes = {
103102
}
104103
},
105104

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.
105+
// `arrayOf` 와 `objectOf 에 사용자 정의 유효성 검사기를 적용할 수 있습니다.
106+
// 검사 실패 시에는 에러(Error) 객체를 반환해야 합니다.
107+
// 유효성 검사기는 배열(array) 혹은 객체의 각 키(key)에 대하여 호출될 것입니다.
108+
// 유효성 검사기의 첫 두 개의 변수는 배열 혹은 객체 자신과 현재 아이템의 키입니다.
109+
111110
customArrayProp: PropTypes.arrayOf(function(propValue, key, componentName, location, propFullName) {
112111
if (!/matchme/.test(propValue[key])) {
113112
return new Error(
@@ -119,16 +118,16 @@ MyComponent.propTypes = {
119118
};
120119
```
121120

122-
### Requiring Single Child {#requiring-single-child}
121+
### 하나의 자식만 요구하기 {#requiring-single-child}
123122

124-
With `PropTypes.element` you can specify that only a single child can be passed to a component as children.
123+
`PropTypes.element`를 이용하여 컴포넌트의 자식들(Children)에 단 하나의 자식(Child)만이 전달될 수 있도록 명시할 수 있습니다.
125124

126125
```javascript
127126
import PropTypes from 'prop-types';
128127

129128
class MyComponent extends React.Component {
130129
render() {
131-
// This must be exactly one element or it will warn.
130+
// 이것은 반드시 하나의 엘리먼트여야 합니다. 아니라면, 경고(warn)가 일어날 것입니다.
132131
const children = this.props.children;
133132
return (
134133
<div>
@@ -143,9 +142,9 @@ MyComponent.propTypes = {
143142
};
144143
```
145144

146-
### Default Prop Values {#default-prop-values}
145+
### 초기 Prop {#default-prop-values}
147146

148-
You can define default values for your `props` by assigning to the special `defaultProps` property:
147+
`defaultProps` 프로퍼티를 할당함으로써 `props`의 초깃값을 정의할 수 있습니다:
149148

150149
```javascript
151150
class Greeting extends React.Component {
@@ -156,19 +155,19 @@ class Greeting extends React.Component {
156155
}
157156
}
158157

159-
// Specifies the default values for props:
158+
// props의 초깃값을 정의합니다.
160159
Greeting.defaultProps = {
161160
name: 'Stranger'
162161
};
163162

164-
// Renders "Hello, Stranger":
163+
// "Hello, Stranger"를 랜더링 합니다.
165164
ReactDOM.render(
166165
<Greeting />,
167166
document.getElementById('example')
168167
);
169168
```
170169

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).
170+
만약 당신이 [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/)와 같은 Babel 변환(transform)을 사용하고 있다면, `defaultProps`React 컴포넌트 클래스 내의 정적 프로퍼티로 선언 할 수도 있습니다. 이 문법은 아직 완성되지 않았으므로 브라우저에서 작동하기 위해서는 컴파일링 작업이 필요합니다. 더 자세한 정보를 위해서 [class fields proposal](https://github.com/tc39/proposal-class-fields)를 확인해 주시길 바랍니다.
172171

173172
```javascript
174173
class Greeting extends React.Component {
@@ -184,4 +183,4 @@ class Greeting extends React.Component {
184183
}
185184
```
186185

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`.
186+
`defaultProps``this.props.name`의 값이 부모 컴포넌트에 의해 명시되지 않았을 때 값을 갖도록 할 것입니다. `propTypes`의 타입 확인은 `defaultProps`에도 적용되게 하기 위하여 `defaultProps`가 처리된 뒤에 일어날 것입니다.

0 commit comments

Comments
 (0)