forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Support for useTransition
Summary: UseTransition is a builtin hook that returns a stable value, like useState. This PR represents that in Forget, and marks the startTransition function as stable. ghstack-source-id: 0e76a64f2d0c86a4eb55c620922b4698250bb5c3 Pull Request resolved: facebook#30681
- Loading branch information
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...xtures/compiler/preserve-memo-validation/preserve-use-memo-transition.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @validatePreserveExistingMemoizationGuarantees | ||
import {useCallback, useTransition} from 'react'; | ||
|
||
function useFoo() { | ||
const [t, start] = useTransition(); | ||
|
||
return useCallback(() => { | ||
start(); | ||
}, []); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees | ||
import { useCallback, useTransition } from "react"; | ||
|
||
function useFoo() { | ||
const $ = _c(1); | ||
const [t, start] = useTransition(); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = () => { | ||
start(); | ||
}; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) "[[ function params=0 ]]" |
15 changes: 15 additions & 0 deletions
15
.../src/__tests__/fixtures/compiler/preserve-memo-validation/preserve-use-memo-transition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @validatePreserveExistingMemoizationGuarantees | ||
import {useCallback, useTransition} from 'react'; | ||
|
||
function useFoo() { | ||
const [t, start] = useTransition(); | ||
|
||
return useCallback(() => { | ||
start(); | ||
}, []); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; |