Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/content/reference/react-compiler/gating.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ title: gating

---

## Reference {/*reference*/}
## 参考 {/*reference*/}

### `gating` {/*gating*/}

为已编译函数配置运行时特性开关的 gating。

#### Type {/*type*/}
#### 类型 {/*type*/}

```
{
Expand Down Expand Up @@ -62,7 +62,7 @@ title: gating
```js
// src/utils/feature-flags.js
export function shouldUseCompiler() {
// your logic here
// 此处是你的逻辑
return getFeatureFlag('react-compiler-enabled');
}
```
Expand Down Expand Up @@ -90,8 +90,8 @@ function Button(props) {
import { shouldUseCompiler } from './src/utils/feature-flags';

const Button = shouldUseCompiler()
? function Button_optimized(props) { /* compiled version */ }
: function Button_original(props) { /* original version */ };
? function Button_optimized(props) { /* 编译后的版本 */ }
: function Button_original(props) { /* 源版本 */ };
```

注意,gating 函数在模块加载时只会执行一次,因此一旦 JS 包被解析并执行,组件的选择将在本次浏览器会话的剩余时间内保持不变。
Expand Down
4 changes: 2 additions & 2 deletions src/content/reference/react-compiler/target.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ npm install react-compiler-runtime@latest
2. 配置 target:

```js
// For React 18
// 对于 React 18
{
target: '18'
}

// For React 17
// 对于 React 17
{
target: '17'
}
Expand Down