Skip to content

Commit 36ca68d

Browse files
authored
Merge branch 'master' into faq
2 parents 20a0d14 + 70c0fb3 commit 36ca68d

File tree

4 files changed

+187
-17
lines changed

4 files changed

+187
-17
lines changed

TRANSLATION.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
1-
# Japanese Translation
1+
# reactjs.org 日本語翻訳者向け翻訳作業ガイドライン
22

3-
Translation Progress: https://github.com/reactjs/ja.reactjs.org/issues/4
3+
まだ作業途中のため問題点や齟齬がある可能性があります。何かあった場合はご指摘をお願いします。
44

5-
# Style Guide
5+
## 環境のセットアップ
66

7-
[TODO]
7+
README.md にある通りですが、さらなる簡略版は以下の通りです。
8+
9+
1. Git, Node, Yarn をそれぞれ準備して ja.reactjs.org (のフォーク)をクローン
10+
2. `yarn` で依存物をインストール(`yarn.lock` が更新された場合は適宜これをくり返す)
11+
3. `yarn dev` でローカルウェブサーバーが立ち上がるのを確認
12+
4. `content` の中身の Markdown ファイルをテキストエディタで編集
13+
5. ブラウザで確認
14+
15+
## 作業の重複を防ぐための宣言
16+
17+
当面は https://github.com/reactjs/ja.reactjs.org/issues/4 を参照しつつ、他の人と被らないように配慮しながら作業を行ってください。
18+
19+
## スタイルの自動チェック
20+
21+
`yarn lint:text` で、基本的な文法(全角英数を使わない、句読点の統一)チェックが走ります。
22+
コミット・PR作成の前にはエラーが出ないようにしてください。
23+
24+
## 全般的なこと
25+
26+
- 「です」「ます」調で書く(箇条書きの中など特殊な文脈を除く)。
27+
- カッコは内部に和文を含む場合は全角、英数字のみ含む場合(特に原文の単語を示す場合など)は半角とする。
28+
- 半角開きカッコの前と半角閉じカッコの後には半角スペースを入れる。ただし別の約物と直接隣接している場合は不要。
29+
> ```
30+
> 避難ハッチ␣(escape hatch)␣を(必要に応じて)利用します。
31+
> ```
32+
33+
- 英数字と和文との間には半角スペースを入れる。ただし他の約物(特に句読点 。, 、)と直接隣接している場合は不要。
34+
35+
> ```
36+
> React␣の␣API␣で、`fooBar`␣を␣1␣回実行。
37+
> ```
38+
39+
- 和文内で文の一部として使う記号・約物類は原則全角とする。`「`, `」`, `、`, `。`, `:`, `!`, `?`, `/` などが該当する。
40+
- 用例の直前の行で行末に現れるコロンについても全角とする。ただしこれは毎回使うべきというわけではない。文が途切れる場合は `:` が必要だが、不自然にならないのであれば、句点 `。` で終えても構わない。
41+
- 英文から飛躍した意訳や表現の追加・改変を行わない。一方で分かりづらくなるような逐語訳もしない。
42+
- ひとまず、リンク先の URL は変えない。(MDN などについては後でまとめて日本語版へのリンクに置換するかもしれませんが、まとめてやる方が間違いも少ないと思われるので、気にしないでいいです)
43+
- `#` で始まる見出しを翻訳すると現時点では自動生成されるアンカー (`<a id="#...">`) が変わってしまい、ページ内の見出しへのリンクが壊れてしまうが、これもひとまず気にしないでおく。(これについては [こちら](https://github.com/reactjs/reactjs.org/issues/1608) で検討中です)
44+
- 和文に対する `*強調*`(`<em>強調</em>` に変換される)がうまく表示されない(日本語フォントに斜体が適用されないため)が、ひとまず原文通りに強調を残す形で翻訳する。(恐らく CSS を弄って解決できるはず)
45+
- ごく一般的な日本語表記に関して困ったら概ね公用文作成の要領などに準ずるが、カタカナ語の末尾の長音符については JIS Z 8301 の推奨に従う。そこまで目くじらを立てなくてよいが、基本は要するに以下の通り。
46+
- 3音以上の場合のみ、片仮名語の末尾の長音符を原則省略。「エコー」「マナー」「ハンドラ」「プロパティ」
47+
- ただし「レンダー」だけは例外で、常に「レンダー」と伸ばす。
48+
- 補助動詞(~てください・~てみる・~ておく・~てくる・~てしまう、など)はかな書き。
49+
- 語彙化した副詞はなるべくかな書き。「ついに」「まれに」「ときに」「ようやく」「おそらく」など。
50+
51+
## 用語の統一
52+
53+
作成中です。
54+
55+
ひとまず https://github.com/reactjs/ja.reactjs.org/issues/3 を参照してください。

content/docs/cdn-links.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
---
22
id: cdn-links
3-
title: CDN Links
3+
title: CDN リンク
44
permalink: docs/cdn-links.html
55
prev: create-a-new-react-app.html
66
next: hello-world.html
77
---
88

9-
Both React and ReactDOM are available over a CDN.
9+
React および ReactDOM CDN を介して利用することができます。
1010

1111
```html
1212
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
1313
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
1414
```
1515

16-
The versions above are only meant for development, and are not suitable for production. Minified and optimized production versions of React are available at:
16+
上記のバージョンは開発のためだけのものであり、本番環境には適していません。圧縮・最適化された本番バージョンの React は下記のリンクから利用できます。
1717

1818
```html
1919
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
2020
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
2121
```
2222

23-
To load a specific version of `react` and `react-dom`, replace `16` with the version number.
23+
特定のバージョンの `react` `react-dom` をロードする場合は、`16` の部分をバージョン番号で置き換えてください。
2424

25-
### Why the `crossorigin` Attribute?
25+
### なぜ `crossorigin` 属性が必要なのか?
2626

27-
If you serve React from a CDN, we recommend to keep the [`crossorigin`](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) attribute set:
27+
CDN を使って React の機能を提供する場合、[`crossorigin`](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) 属性を設定することをお勧めします。
2828

2929
```html
3030
<script crossorigin src="..."></script>
3131
```
3232

33-
We also recommend to verify that the CDN you are using sets the `Access-Control-Allow-Origin: *` HTTP header:
33+
利用している CDN `Access-Control-Allow-Origin: *` という HTTP ヘッダを設定していることを確認することもお勧めします。
3434

3535
![Access-Control-Allow-Origin: *](../images/docs/cdn-cors-header.png)
3636

37-
This enables a better [error handling experience](/blog/2017/07/26/error-handling-in-react-16.html) in React 16 and later.
37+
これにより React 16 以降でより優れた[エラーハンドリング](/blog/2017/07/26/error-handling-in-react-16.html)を利用できます。

content/docs/reference-javascript-environment-requirements.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
id: javascript-environment-requirements
3-
title: JavaScript Environment Requirements
3+
title: JavaScript 環境の要件
44
layout: docs
55
category: Reference
66
permalink: docs/javascript-environment-requirements.html
77
---
88

9-
React 16 depends on the collection types [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) and [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set). If you support older browsers and devices which may not yet provide these natively (e.g. IE &lt; 11) or which have non-compliant implementations (e.g. IE 11), consider including a global polyfill in your bundled application, such as [core-js](https://github.com/zloirock/core-js) or [babel-polyfill](https://babeljs.io/docs/usage/polyfill/).
9+
React 16 はコレクション型 [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) および [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) に依存しています。これらの機能をネイティブに提供しない(IE 11 未満など)、または標準非準拠な挙動をする(IE 11 など)古いブラウザやデバイスをサポートする場合は、[core-js](https://github.com/zloirock/core-js) [babel-polyfill](https://babeljs.io/docs/en/babel-polyfill/) などのような、グローバル環境のポリフィルをバンドルしたアプリケーションに含めることを検討してください。
1010

11-
A polyfilled environment for React 16 using core-js to support older browsers might look like:
11+
古いブラウザをサポートするため、core-js を利用してポリフィルを含めた React 16 向けの環境は次のようになります。
1212

1313
```js
1414
import 'core-js/es6/map';
@@ -23,8 +23,8 @@ ReactDOM.render(
2323
);
2424
```
2525

26-
React also depends on `requestAnimationFrame` (even in test environments).
27-
You can use the [raf](https://www.npmjs.com/package/raf) package to shim `requestAnimationFrame`:
26+
React は(テスト環境であっても)`requestAnimationFrame` に依存します。
27+
`requestAnimationFrame` の役割を補うため [raf](https://www.npmjs.com/package/raf) を使用します。
2828

2929
```js
3030
import 'raf/polyfill';
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
title: Invalid Hook Call Warning
3+
layout: single
4+
permalink: warnings/invalid-hook-call-warning.html
5+
---
6+
7+
You are probably here because you got the following error message:
8+
9+
> Hooks can only be called inside the body of a function component.
10+
11+
There are three common reasons you might be seeing it:
12+
13+
1. You might have **mismatching versions** of React and React DOM.
14+
2. You might be **breaking the [Rules of Hooks](/docs/hooks-rules.html)**.
15+
3. You might have **more than one copy of React** in the same app.
16+
17+
Let's look at each of these cases.
18+
19+
## Mismatching Versions of React and React DOM
20+
21+
You might be using a version of `react-dom` (&lt; 16.8.0) or `react-native` (&lt; 0.60) that doesn't yet support Hooks. You can run `npm ls react-dom` or `npm ls react-native` in your application folder to check which version you're using. If you find more than one of them, this might also create problems (more on that below).
22+
23+
## Breaking the Rules of Hooks
24+
25+
You can only call Hooks **while React is rendering a function component**:
26+
27+
* ✅ Call them at the top level in the body of a function component.
28+
* ✅ Call them at the top level in the body of a [custom Hook](/docs/hooks-custom.html).
29+
30+
**Learn more about this in the [Rules of Hooks](/docs/hooks-rules.html).**
31+
32+
```js{2-3,8-9}
33+
function Counter() {
34+
// ✅ Good: top-level in a function component
35+
const [count, setCount] = useState(0);
36+
// ...
37+
}
38+
39+
function useWindowWidth() {
40+
// ✅ Good: top-level in a custom Hook
41+
const [width, setWidth] = useState(window.innerWidth);
42+
// ...
43+
}
44+
```
45+
46+
To avoid confusion, it’s **not** supported to call Hooks in other cases:
47+
48+
* 🔴 Do not call Hooks in class components.
49+
* 🔴 Do not call in event handlers.
50+
* 🔴 Do not call Hooks inside functions passed to `useMemo`, `useReducer`, or `useEffect`.
51+
52+
If you break these rules, you might see this error.
53+
54+
```js{3-4,11-12,20-21}
55+
function Bad1() {
56+
function handleClick() {
57+
// 🔴 Bad: inside an event handler (to fix, move it outside!)
58+
const theme = useContext(ThemeContext);
59+
}
60+
// ...
61+
}
62+
63+
function Bad2() {
64+
const style = useMemo(() => {
65+
// 🔴 Bad: inside useMemo (to fix, move it outside!)
66+
const theme = useContext(ThemeContext);
67+
return createStyle(theme);
68+
});
69+
// ...
70+
}
71+
72+
class Bad3 extends React.Component {
73+
render() {
74+
// 🔴 Bad: inside a class component
75+
useEffect(() => {})
76+
// ...
77+
}
78+
}
79+
```
80+
81+
You can use the [`eslint-plugin-react-hooks` plugin](https://www.npmjs.com/package/eslint-plugin-react-hooks) to catch some of these mistakes.
82+
83+
>Note
84+
>
85+
>[Custom Hooks](/docs/hooks-custom.html) *may* call other Hooks (that's their whole purpose). This works because custom Hooks are also supposed to only be called while a function component is rendering.
86+
87+
88+
## Duplicate React
89+
90+
In order for Hooks to work, the `react` import from your application code needs to resolve to the same module as the `react` import from inside the `react-dom` package.
91+
92+
If these `react` imports resolve to two different exports objects, you will see this warning. This may happen if you **accidentally end up with two copies** of the `react` package.
93+
94+
If you use Node for package management, you can run this check in your project folder:
95+
96+
npm ls react
97+
98+
If you see more than one React, you'll need to figure out why this happens and fix your dependency tree. For example, maybe a library you're using incorrectly specifies `react` as a dependency (rather than a peer dependency). Until that library is fixed, [Yarn resolutions](https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) is one possible workaround.
99+
100+
You can also try to debug this problem by adding some logs and restarting your development server:
101+
102+
```js
103+
// Add this in node_modules/react-dom/index.js
104+
window.React1 = require('react');
105+
106+
// Add this in your component file
107+
require('react-dom');
108+
window.React2 = require('react');
109+
console.log(window.React1 === window.React2);
110+
```
111+
112+
If it prints `false` then you might have two Reacts and need to figure out why that happened. [This issue](https://github.com/facebook/react/issues/13991) includes some common reasons encountered by the community.
113+
114+
This problem can also come up when you use `npm link` or an equivalent. In that case, your bundler might "see" two Reacts — one in application folder and one in your library folder. Assuming `myapp` and `mylib` are sibling folders, one possible fix is to run `npm link ../myapp/node_modules/react` from `mylib`. This should make the library use the application's React copy.
115+
116+
>Note
117+
>
118+
>In general, React supports using multiple independent copies on one page (for example, if an app and a third-party widget both use it). It only breaks if `require('react')` resolves differently between the component and the `react-dom` copy it was rendered with.
119+
120+
## Other Causes
121+
122+
If none of this worked, please comment in [this issue](https://github.com/facebook/react/issues/13991) and we'll try to help. Try to create a small reproducing example — you might discover the problem as you're doing it.

0 commit comments

Comments
 (0)