Skip to content

Commit 8730213

Browse files
authored
Merge branch 'master' into faq_versioning
2 parents 8c40402 + 83b782d commit 8730213

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

content/docs/faq-ajax.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,50 @@ class MyComponent extends React.Component {
8282
}
8383
}
8484
```
85+
86+
Here is the equivalent with [Hooks](https://reactjs.org/docs/hooks-intro.html):
87+
88+
```js
89+
function MyComponent() {
90+
const [error, setError] = useState(null);
91+
const [isLoaded, setIsLoaded] = useState(false);
92+
const [items, setItems] = useState([]);
93+
94+
// Note: the empty deps array [] means
95+
// this useEffect will run once
96+
// similar to componentDidMount()
97+
useEffect(() => {
98+
fetch("https://api.example.com/items")
99+
.then(res => res.json())
100+
.then(
101+
(result) => {
102+
setIsLoaded(true);
103+
setItems(result.items);
104+
},
105+
// Note: it's important to handle errors here
106+
// instead of a catch() block so that we don't swallow
107+
// exceptions from actual bugs in components.
108+
(error) => {
109+
setIsLoaded(true);
110+
setError(error);
111+
}
112+
)
113+
}, [])
114+
115+
if (error) {
116+
return <div>Error: {error.message}</div>;
117+
} else if (!isLoaded) {
118+
return <div>Loading...</div>;
119+
} else {
120+
return (
121+
<ul>
122+
{items.map(item => (
123+
<li key={item.name}>
124+
{item.name} {item.price}
125+
</li>
126+
))}
127+
</ul>
128+
);
129+
}
130+
}
131+
```

content/docs/forms.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ class NameForm extends React.Component {
6868

6969
`value` 어트리뷰트는 폼 엘리먼트에 설정되므로 표시되는 값은 항상 `this.state.value`가 되고 React state는 신뢰 가능한 단일 출처 (single source of truth)가 됩니다. React state를 업데이트하기 위해 모든 키 입력에서 `handleChange`가 동작하기 때문에 사용자가 입력할 때 보여지는 값이 업데이트됩니다.
7070

71-
제어 컴포넌트로 사용하면 모든 state 변화는 연관된 핸들러를 가집니다. 이것을 통해 사용자 입력을 수정하거나 유효성을 검사하는 것이 간단해집니다. 예를 들어, 이름이 모두 대문자로 쓰여지게 하고 싶다면 `handleChange`를 다음과 같이 사용할 수 있습니다.
72-
73-
```javascript{2}
74-
handleChange(event) {
75-
this.setState({value: event.target.value.toUpperCase()});
76-
}
77-
```
71+
제어 컴포넌트로 사용하면, input의 값은 항상 React state에 의해 결정됩니다. 코드를 조금 더 작성해야 한다는 의미이지만, 다른 UI 엘리먼트에 input의 값을 전달하거나 다른 이벤트 핸들러에서 값을 재설정할 수 있습니다.
7872

7973
## textarea 태그 {#the-textarea-tag}
8074

content/docs/strict-mode.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ class MyComponent extends React.Component {
9898

9999
위의 메서드들은 여러 번 호출될 수 있기 때문에, 부작용을 포함하지 않는 것이 중요합니다. 이 규칙을 무시할 경우, 메모리 누수 혹은 잘못된 애플리케이션 상태 등 다양한 문제를 일으킬 가능성이 있습니다. 불행히도, 보통 이러한 문제들은 [예측한 대로 동작하지 않기 때문](https://ko.wikipedia.org/wiki/%EA%B2%B0%EC%A0%95%EB%A1%A0%EC%A0%81_%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98)에 발견하는 것이 어려울 수 있습니다.
100100

101-
<<<<<<< HEAD
102101
Strict 모드가 자동으로 부작용을 찾아주는 것은 불가능합니다. 하지만, 조금 더 예측할 수 있게끔 만들어서 문제가 되는 부분을 발견할 수 있게 도와줍니다. 이는 아래의 함수를 의도적으로 이중으로 호출하여 찾을 수 있습니다.
103102

104103
* 클래스 컴포넌트의 `constructor`, `render` 그리고 `shouldComponentUpdate` 메서드

examples/uncontrolled-components/input-type-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class FileInput extends React.Component {
66
this.fileInput = React.createRef();
77
}
88
handleSubmit(event) {
9-
// highlight-range{4}
9+
// highlight-range{3}
1010
event.preventDefault();
1111
alert(
1212
`Selected file - ${this.fileInput.current.files[0].name}`

0 commit comments

Comments
 (0)