Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Exception using both input and useState #24414

Closed
yh4922 opened this issue Apr 21, 2022 · 4 comments
Closed

Bug: Exception using both input and useState #24414

yh4922 opened this issue Apr 21, 2022 · 4 comments
Labels
Resolution: Expected Behavior Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@yh4922
Copy link

yh4922 commented Apr 21, 2022

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Use const [val, setVal] = useState(""); to bind the input value After calling the setVal method in the onChange callback, the val value cannot be obtained by printing the latest value
The value obtained is the last modified value

What is expected?

Expect to get the latest val after setVal()

What is actually happening?

But you can only get the value of the previous modification

Environment Info
React 18.0.0
System win10 21H2 19044.1526
Browser Google Chrome 100.0.4896.88
@yh4922 yh4922 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 21, 2022
@khareyash05
Copy link

i would like to work on this one @yh4922

@yh4922
Copy link
Author

yh4922 commented Apr 21, 2022

@khareyash05 I have the codesandbox minimal reproduction code above

@webcarrot
Copy link

It's expected behavior.
reactjs/rfcs#201

@eps1lon
Copy link
Collaborator

eps1lon commented Apr 23, 2022

This is expected behavior that's currently not explicitly documented. However, the beta docs have a dedicated section for this behavior:

Calling the set function does not change the current state in the already executing code: [...]

-- https://beta.reactjs.org/apis/usestate#adding-state-to-a-component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Expected Behavior Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

4 participants