-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider dispatch function from useActionState non-reactive (#29917)
Updated version of #29758 removing `useFormState` since that was the previous name for `useActionState`. --------- Co-authored-by: Hieu Do <hieudn.uh@gmail.com>
- Loading branch information
1 parent
107a2f8
commit ddcecbb
Showing
7 changed files
with
129 additions
and
13 deletions.
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
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
57 changes: 57 additions & 0 deletions
57
.../fixtures/compiler/useActionState-dispatch-considered-as-non-reactive.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,57 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
import { useActionState } from "react"; | ||
|
||
function Component() { | ||
const [actionState, dispatchAction] = useActionState(); | ||
const onSubmitAction = () => { | ||
dispatchAction(); | ||
}; | ||
return <Foo onSubmitAction={onSubmitAction} />; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; | ||
import { useActionState } from "react"; | ||
|
||
function Component() { | ||
const $ = _c(1); | ||
const [actionState, dispatchAction] = useActionState(); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
const onSubmitAction = () => { | ||
dispatchAction(); | ||
}; | ||
|
||
t0 = <Foo onSubmitAction={onSubmitAction} />; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
return t0; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; | ||
|
||
``` | ||
### Eval output | ||
(kind: ok) |
16 changes: 16 additions & 0 deletions
16
...ler/src/__tests__/fixtures/compiler/useActionState-dispatch-considered-as-non-reactive.js
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,16 @@ | ||
import { useActionState } from "react"; | ||
|
||
function Component() { | ||
const [actionState, dispatchAction] = useActionState(); | ||
const onSubmitAction = () => { | ||
dispatchAction(); | ||
}; | ||
return <Foo onSubmitAction={onSubmitAction} />; | ||
} | ||
|
||
function Foo() {} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Component, | ||
params: [], | ||
}; |