Skip to content

Commit ac96c1b

Browse files
committed
API docs for useDeferredValue's initialValue
Updates the API docs for `useDeferredValue` to include the `initialValue` option, added in facebook/react#27500. This feature is slated for release in React 19.
1 parent 342fddb commit ac96c1b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/content/reference/react/useDeferredValue.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const deferredValue = useDeferredValue(value)
1818

1919
## Reference {/*reference*/}
2020

21-
### `useDeferredValue(value)` {/*usedeferredvalue*/}
21+
### `useDeferredValue(value, initialValue?)` {/*usedeferredvalue*/}
2222

2323
Call `useDeferredValue` at the top level of your component to get a deferred version of that value.
2424

@@ -37,10 +37,19 @@ function SearchPage() {
3737
#### Parameters {/*parameters*/}
3838

3939
* `value`: The value you want to defer. It can have any type.
40+
* **optional** `initialValue`: A value to use during the initial render of a component. If this option is omitted, `useDeferredValue` will not defer during the initial render, because there's no previous version of `value` that it can render instead.
41+
4042

4143
#### Returns {/*returns*/}
4244

43-
During the initial render, the returned deferred value will be the same as the value you provided. During updates, React will first attempt a re-render with the old value (so it will return the old value), and then try another re-render in the background with the new value (so it will return the updated value).
45+
Returns either `value`, the old `value` that was previously rendered to the screen, or `initialValue`, depending on the scenario:
46+
47+
- During the initial render...
48+
- If `initialValue` _is_ provided, it first returns `initialValue`, then spawns a deferred render to switch to `value`.
49+
- If `initialValue` _is not_ provided, it returns `value`, and does not spawn a deferred render.
50+
- During an update...
51+
- If the update _is_ the result of a Transition, it returns the new `value`, and does not spawn a deferred render.
52+
- If the update _is not_ the result of a Transition, it first returns the old `value`, then spawns a deferred render to switch to the new `value`.
4453

4554
#### Caveats {/*caveats*/}
4655

0 commit comments

Comments
 (0)