Skip to content

Commit

Permalink
docs: add derive attention
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Feb 28, 2024
1 parent 17d0bf7 commit 78e3701
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/docs/guide/derive.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,28 @@ witness.run();
// 呼叫 fnItem 配置的异步函数
witness.runTask();
```

### 注意事项

`derive`回调里的依赖必须提前声明,不能放到条件语句里,否则可能照成依赖丢失。

- 错误示例

```ts
const result = derive(() => {
if( state.x ) return 2;
return state.y + 1;
});
```

- 正确示例

```ts
const result = derive(() => {
const { x, y } = state;
if (x) return 2;
y + 1;
});
```


0 comments on commit 78e3701

Please sign in to comment.