Skip to content
Open
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
8 changes: 5 additions & 3 deletions src/api/reactivity-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,23 @@ Creates a customized ref with explicit control over its dependency tracking and
- **Type**

```ts
function customRef<T>(factory: CustomRefFactory<T>): Ref<T>
function customRef<T, S = T>(factory: CustomRefFactory<T, S>): Ref<T, S>

type CustomRefFactory<T> = (
type CustomRefFactory<T, S = T> = (
track: () => void,
trigger: () => void
) => {
get: () => T
set: (value: T) => void
set: (value: S) => void
}
```

- **Details**

`customRef()` expects a factory function, which receives `track` and `trigger` functions as arguments and should return an object with `get` and `set` methods.

The setter can accept a different type from the getter's return type. The setter type defaults to the getter type.

In general, `track()` should be called inside `get()`, and `trigger()` should be called inside `set()`. However, you have full control over when they should be called, or whether they should be called at all.

- **Example**
Expand Down