Skip to content

Commit 93077f9

Browse files
docs(website): add updated derived docs
1 parent 937098d commit 93077f9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Derive
22

3+
You can add derived state to your application. You access derived state like any other value, there is not need to call it as a function. The derived value is cached and will only update when any accessed state changes.
4+
35
```marksy
46
h(Example, { name: "api/derive" })
57
```
68

7-
You can add derived state to your application. You access derived state like any other value, there is not need to call it as a function. The derived value is cached and will only update when any accessed state changes.
9+
The function defining your derived state receives two arguments. The first argument is the object the derived function is attached to. Ideally you use this argument to produce your derived state, though you can access the second argument which is the root state of the application. The root state allows you to access any state.
10+
11+
12+
```marksy
13+
h(Notice, null, "Accessing **rootState** might cause unnecessary updates to the derived function as it will track more state, though typically not an issue")
14+
```

packages/overmind-website/examples/api/derive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type Item = {
1313
1414
export const items: Item[] = []
1515
16-
export const completedItems: Derive<Item[]> = state =>
16+
export const completedItems: Derive<Item[]> = (state, rootState) =>
1717
state.items.filter(item => item.completed)
1818
`,
1919
},
@@ -26,7 +26,7 @@ import * as derived from './derived'
2626
2727
export const items = []
2828
29-
export const completedItems = state =>
29+
export const completedItems = (state, rootState) =>
3030
state.items.filter(item => item.completed)
3131
`,
3232
},

0 commit comments

Comments
 (0)