You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ad5dad6
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/lints/incompatible-library.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,19 +4,19 @@ title: incompatible-library
4
4
5
5
<Intro>
6
6
7
-
Validates against usage of libraries which are incompatible with memoization (manual or automatic).
7
+
メモ化(手動でも自動でも)と互換性のないライブラリを使っていないか検証します。
8
8
9
9
</Intro>
10
10
11
11
<Note>
12
12
13
-
These libraries were designed before React's memoization rules were fully documented. They made the correct choices at the time to optimize for ergonomic ways to keep components just the right amount of reactive as app state changes. While these legacy patterns worked, we have since discovered that it's incompatible with React's programming model. We will continue working with library authors to migrate these libraries to use patterns that follow the Rules of React.
Some libraries use patterns that aren't supported by React. When the linter detects usages of these APIs from a [known list](https://github.com/react/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts), it flags them under this rule. This means that React Compiler can automatically skip over components that use these incompatible APIs, in order to avoid breaking your app.
19
+
一部のライブラリは、React がサポートしていないパターンを使っています。リンタは、[既知のリスト](https://github.com/react/react/blob/main/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts)にある API の使用を検出すると、このルールの違反として報告します。これにより、React Compiler は、互換性のない API を使うコンポーネントを自動的にスキップして、アプリが動作しなくなることを防げます。
20
20
21
21
```js
22
22
// Example of how memoization breaks with these libraries
@@ -30,17 +30,17 @@ function Form() {
30
30
}
31
31
```
32
32
33
-
React Compiler automatically memoizes values following the Rules of React. If something breaks with manual `useMemo`, it will also break the compiler's automatic optimization. This rule helps identify these problematic patterns.
#### Designing APIs that follow the Rules of React {/*designing-apis-that-follow-the-rules-of-react*/}
37
+
#### React のルールに従う API の設計 {/*designing-apis-that-follow-the-rules-of-react*/}
38
38
39
-
One question to think about when designing a library API or hook is whether calling the API can be safely memoized with `useMemo`. If it can't, then both manual and React Compiler memoizations will break your user's code.
39
+
ライブラリの API やフックを設計する際に考えるべきことのひとつは、その API の呼び出しを `useMemo` で安全にメモ化できるかどうかです。できなければ、手動のメモ化であれ React Compiler によるメモ化であれ、ユーザのコードは動作しなくなります。
40
40
41
-
For example, one such incompatible pattern is "interior mutability". Interior mutability is when an object or function keeps its own hidden state that changes over time, even though the reference to it stays the same. Think of it like a box that looks the same on the outside but secretly rearranges its contents. React can't tell anything changed because it only checks if you gave it a different box, not what's inside. This breaks memoization, since React relies on the outer object (or function) changing if part of its value has changed.
As a rule of thumb, when designing React APIs, think about whether `useMemo`would break it:
43
+
React の API を設計する際の目安として、以下のように `useMemo`を使っても動作するかどうか考えてください。
44
44
45
45
```js
46
46
functionComponent() {
@@ -50,7 +50,7 @@ function Component() {
50
50
}
51
51
```
52
52
53
-
Instead, design APIs that return immutable state and use explicit update functions:
53
+
代わりに、イミュータブルな状態を返し、明示的な更新関数を使う API を設計してください。
54
54
55
55
```js
56
56
// ✅ Good: Return immutable state that changes reference when updated
@@ -73,9 +73,9 @@ function Component() {
73
73
74
74
</DeepDive>
75
75
76
-
### Invalid {/*invalid*/}
76
+
### 無効な例 {/*invalid*/}
77
77
78
-
Examples of incorrect code for this rule:
78
+
このルールに違反するコードの例です。
79
79
80
80
```js
81
81
// ❌ react-hook-form `watch`
@@ -101,7 +101,7 @@ function Component({data}) {
101
101
102
102
#### MobX {/*mobx*/}
103
103
104
-
MobX patterns like `observer`also break memoization assumptions, but the linter does not yet detect them. If you rely on MobX and find that your app doesn't work with React Compiler, you may need to use the `"use no memo" directive`.
104
+
MobX の `observer`などのパターンもメモ化の前提に反しますが、リンタはまだ検出できません。MobX を使っていて、React Compiler でアプリが動作しなくなる場合は、`"use no memo"` ディレクティブを使う必要があるかもしれません。
Some other libraries do not yet have alternative APIs that are compatible with React's memoization model. If the linter doesn't automatically skip over your components or hooks that call these APIs, please [file an issue](https://github.com/react/react/issues) so we can add it to the linter.
138
+
ほかにも、React のメモ化モデルと互換性のある代替 API がまだないライブラリがあります。これらの API を呼び出すコンポーネントやフックがリンタによって自動的にスキップされない場合は、リンタに追加できるよう、[問題を報告](https://github.com/react/react/issues)してください。
0 commit comments