Skip to content

Commit 67aad91

Browse files
ginpeikoba04
authored andcommitted
translate FAQ - Component State (#105)
* translate Component State * update words * misc * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * Update content/docs/faq-state.md Co-Authored-By: ginpei <[email protected]> * spaces between en and ja
1 parent d97c593 commit 67aad91

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

content/docs/faq-state.md

+41-41
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
11
---
22
id: faq-state
3-
title: Component State
3+
title: コンポーネントの state
44
permalink: docs/faq-state.html
55
layout: docs
66
category: FAQ
77
---
88

9-
### What does `setState` do? {#what-does-setstate-do}
9+
### `setState` は何をしているのですか? {#what-does-setstate-do}
1010

11-
`setState()` schedules an update to a component's `state` object. When state changes, the component responds by re-rendering.
11+
`setState()` はコンポーネントの `state` オブジェクト更新をスケジュールします。state が更新されると、コンポーネントはそれに再レンダーで応じます。
1212

13-
### What is the difference between `state` and `props`? {#what-is-the-difference-between-state-and-props}
13+
### `state` `props` の違いは何ですか? {#what-is-the-difference-between-state-and-props}
1414

15-
[`props`](/docs/components-and-props.html) (short for "properties") and [`state`](/docs/state-and-lifecycle.html) are both plain JavaScript objects. While both hold information that influences the output of render, they are different in one important way: `props` get passed *to* the component (similar to function parameters) whereas `state` is managed *within* the component (similar to variables declared within a function).
15+
[`props`](/docs/components-and-props.html)"properties" を短くしたもの)と [`state`](/docs/state-and-lifecycle.html) は、両方ともプレーンな JavaScript のオブジェクトです。どちらもレンダー結果に影響を及ぼす情報を持ってはいますが、ある重要な一点が異なっています。つまり、`props` は(関数引数のように)コンポーネント**渡されるのに対し、`state` は(関数内で宣言された変数のように)コンポーネント*の内部*で制御されます。
1616

17-
Here are some good resources for further reading on when to use `props` vs `state`:
17+
`props` `state` のどちらをいつ使うべきかについて、こちらでより詳しく読むことができます。
1818
* [Props vs State](https://github.com/uberVU/react-guide/blob/master/props-vs-state.md)
1919
* [ReactJS: Props vs. State](http://lucybain.com/blog/2016/react-state-vs-pros/)
2020

21-
### Why is `setState` giving me the wrong value? {#why-is-setstate-giving-me-the-wrong-value}
21+
### `setState` が誤った値を返すのはなぜですか? {#why-is-setstate-giving-me-the-wrong-value}
2222

23-
In React, both `this.props` and `this.state` represent the *rendered* values, i.e. what's currently on the screen.
23+
React では、`this.props` `this.state` のいずれも、*レンダーされた*もの、つまりスクリーン上の値を表しています。
2424

25-
Calls to `setState` are asynchronous - don't rely on `this.state` to reflect the new value immediately after calling `setState`. Pass an updater function instead of an object if you need to compute values based on the current state (see below for details).
25+
`setState` 呼び出しは非同期です。呼び出し直後から `this.state` が新しい値を反映することを期待しないでください。もし現在の state に基づいた値を計算する必要がある場合は、オブジェクトの代わりに更新関数を渡してください。(詳しくは以下を参照)
2626

27-
Example of code that will *not* behave as expected:
27+
このコード例は期待した通りには*動きません*
2828

2929
```jsx
3030
incrementCount() {
31-
// Note: this will *not* work as intended.
31+
// 補足:これは意図通りに*動きません*
3232
this.setState({count: this.state.count + 1});
3333
}
3434

3535
handleSomething() {
36-
// Let's say `this.state.count` starts at 0.
36+
// `this.state.count` は 0 から始まるとします。
3737
this.incrementCount();
3838
this.incrementCount();
3939
this.incrementCount();
40-
// When React re-renders the component, `this.state.count` will be 1, but you expected 3.
40+
// React がコンポーネントを再レンダーしても、`this.state.count` は意図通りの 3 ではなく 1 になります。
4141

42-
// This is because `incrementCount()` function above reads from `this.state.count`,
43-
// but React doesn't update `this.state.count` until the component is re-rendered.
44-
// So `incrementCount()` ends up reading `this.state.count` as 0 every time, and sets it to 1.
42+
// これは、上記の `incrementCount()` 関数は `this.state.count` の値を読むのですが、
43+
// しかしコンポーネントが再レンダーされるまで React `this.state.count` を更新しないためです。
44+
// そして `incrementCount()` は値が 0 のままの `this.state.count` を毎回読み、そして 1 をセットしてしまいます。
4545

46-
// The fix is described below!
46+
// 対処法は下で説明していますよ!
4747
}
4848
```
4949

50-
See below for how to fix this problem.
50+
この問題を解決するには以下を見てください。
5151

52-
### How do I update state with values that depend on the current state? {#how-do-i-update-state-with-values-that-depend-on-the-current-state}
52+
### どうやって現在の state に依存する値を更新したらいいですか? {#how-do-i-update-state-with-values-that-depend-on-the-current-state}
5353

54-
Pass a function instead of an object to `setState` to ensure the call always uses the most updated version of state (see below).
54+
`setState` へオブジェクトを渡す代わりに関数を渡してください。その関数は常に最新の状態の state を使って呼ばれることが保証されています。(次項参照)
5555

56-
### What is the difference between passing an object or a function in `setState`? {#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate}
56+
### `setState` へオブジェクトを渡すのと関数を渡すのとのでは何が違いますか? {#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate}
5757

58-
Passing an update function allows you to access the current state value inside the updater. Since `setState` calls are batched, this lets you chain updates and ensure they build on top of each other instead of conflicting:
58+
更新関数を渡すと、その関数内で現在の state の値へアクセスできるようになります。`setState` 呼び出しはバッチ処理されるため、更新処理を連結して、それぞれの更新が競合せずに順序だって動作することが保証されます。
5959

6060
```jsx
6161
incrementCount() {
6262
this.setState((state) => {
63-
// Important: read `state` instead of `this.state` when updating.
63+
// 重要:更新には `this.state` ではなく `state` を使います。
6464
return {count: state.count + 1}
6565
});
6666
}
6767

6868
handleSomething() {
69-
// Let's say `this.state.count` starts at 0.
69+
// `this.state.count` は 0 から始まるとします。
7070
this.incrementCount();
7171
this.incrementCount();
7272
this.incrementCount();
7373

74-
// If you read `this.state.count` now, it would still be 0.
75-
// But when React re-renders the component, it will be 3.
74+
// ここで `this.state.count` を読んでもまだ 0 のままです。
75+
// しかし React がコンポーネントを再レンダーするとき、値は 3 になります。
7676
}
7777
```
7878

79-
[Learn more about setState](/docs/react-component.html#setstate)
79+
[setState についてもっと学ぶ](/docs/react-component.html#setstate)
8080

81-
### When is `setState` asynchronous? {#when-is-setstate-asynchronous}
81+
### いつ `setState` は非同期になりますか? {#when-is-setstate-asynchronous}
8282

83-
Currently, `setState` is asynchronous inside event handlers.
83+
現在、`setState` はイベントハンドラの内側では非同期です。
8484

85-
This ensures, for example, that if both `Parent` and `Child` call `setState` during a click event, `Child` isn't re-rendered twice. Instead, React "flushes" the state updates at the end of the browser event. This results in significant performance improvements in larger apps.
85+
例えばクリックイベントの間に `Parent` `Child` の両方が `setState` を呼ぶとき、非同期処理のおかげで `Child` が 2 度レンダーされないことが保証されます。その代わりに React はブラウザイベントの最後に state の更新を「フラッシュ (flush)」します。これにより大規模アプリのパフォーマンスが大幅に向上します。
8686

87-
This is an implementation detail so avoid relying on it directly. In the future versions, React will batch updates by default in more cases.
87+
これは実装の詳細ですので、この仕組みに直接依存しないようにしてください。将来のバージョンにおいて、React はより多くの場合にバッチ更新するようになります。
8888

89-
### Why doesn't React update `this.state` synchronously? {#why-doesnt-react-update-thisstate-synchronously}
89+
### どうして React `this.state` を同期的に更新しないのですか? {#why-doesnt-react-update-thisstate-synchronously}
9090

91-
As explained in the previous section, React intentionally "waits" until all components call `setState()` in their event handlers before starting to re-render. This boosts performance by avoiding unnecessary re-renders.
91+
前項で説明したように、全てのコンポーネントがそのイベントハンドラ内で `setState()` を呼ぶまで、React は再レンダー前に意図的に「待つ」ようになっています。これにより不必要な再レンダーが防がれ、パフォーマンスが向上します。
9292

93-
However, you might still be wondering why React doesn't just update `this.state` immediately without re-rendering.
93+
とはいえ、React がどうして再レンダーなしに `this.state` を即時更新しないのか、まだ疑問に思っているかもしれません。
9494

95-
There are two main reasons:
95+
これには主に 2 つの理由があります。
9696

97-
* This would break the consistency between `props` and `state`, causing issues that are very hard to debug.
98-
* This would make some of the new features we're working on impossible to implement.
97+
* 同期的更新が `props` `state` の間の一貫性を破壊し、非常にデバッグが難しい問題を引き起こしうるため。
98+
* 同期的更新が、我々が取り組んでいる新機能のいくつかを実装不可能にしうるため。
9999

100-
This [GitHub comment](https://github.com/facebook/react/issues/11527#issuecomment-360199710) dives deep into the specific examples.
100+
この [GitHub コメント](https://github.com/facebook/react/issues/11527#issuecomment-360199710)は特定の例について詳しく解説しています。
101101

102-
### Should I use a state management library like Redux or MobX? {#should-i-use-a-state-management-library-like-redux-or-mobx}
102+
### Redux や MobX のような state 管理ライブラリを使うべきでしょうか? {#should-i-use-a-state-management-library-like-redux-or-mobx}
103103

104-
[Maybe.](https://redux.js.org/faq/general#when-should-i-use-redux)
104+
[時には必要かもしれません。](https://redux.js.org/faq/general#when-should-i-use-redux)
105105

106-
It's a good idea to get to know React first, before adding in additional libraries. You can build quite complex applications using only React.
106+
まずは他のライブラリを追加する前に React を理解することをお勧めします。React だけでも非常に複雑なアプリケーションを作り上げることができます。

0 commit comments

Comments
 (0)