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
TypeScript error when using useFormState
#56041
Comments
Linking other issue where workaround has been mentioned 😃 #55919 |
What if i'd wanted to pass arguments to |
– Removed file react.d.ts created to handle open issue vercel/next.js#56041 (comment) and the file defined the type for useFormState broke the React types.
I used // @ts-expect-error and this error displayed in the terminal Attempted import error: 'experimental_useFormState' is not exported from 'react-dom' (imported as 'useFormState'). |
Did you tried to comment with //@ts-ignore ? Are you using Next.js >13.5 version? Here //@ts-ignore running with this version have worked. |
I did try @ts-ignore and got the same error, im having v13.4, do you think the only solution is to update next to v13.5 |
13.4 uses older experimental React version which don’t include this hook. So you need to upgrade to 13.5 to use it 😃 |
|
rm -rf .next |
Hey all, make sure you use the
This fixed it for me (I should have set it up front anyway) and explained the error well. |
I was having the same issue with next.js 13.4. I manually installed next@latest react@latest react-dom@latest and the issue persists. After adding // @ts-ignore on the file above import { experimental_useFormState as useFormState } from "react-dom" seemed to fix the issue for me. |
WorkaroundFor now, just pin these versions of the types packages and the {
"@types/react": "18.2.23",
"@types/react-dom": "18.2.8",
} |
Error still occuring in This made the trick for now:
|
Hello guys To fix linting error I have just changed below packages from: "react": "^18",
"react-dom": "^18",
"@types/react": "^18",
"@types/react-dom": "^18", Into: "react": "18.2.0",
"react-dom": "18.2.0",
"@types/react": "18.2.14",
"@types/react-dom": "18.2.6", |
Hi all, the issue still persists on In particular, import { useFormState, useFormStatus } from "react-dom"; but at runtime both of them are To make things work, I still have to use this workaround: import {
// @ts-expect-error
experimental_useFormState as useFormState,
// @ts-expect-error
experimental_useFormStatus as useFormStatus,
} from "react-dom"; but doing so breaks the type inference on const [formState, formAction] = useFormState(action, initialState);
// ^ any ^ any |
@morellodev try adding
And then use the import as normal:
I'm using the following versions:
|
@jmd01 following exactly that.
|
@jmd01 @shawnmclean The issue we are having is due to a misalignment between the members exported by The canary |
@shawnmclean @morellodev I had to also use the latest next, react, react-dom. This is working for me now:
|
@jmd01
|
As an alternative to the above workarounds, you can use this shim with next@13.5.6: // file: react-dom-shim.ts
import {
//@ts-expect-error
experimental_useFormState,
//@ts-expect-error
experimental_useFormStatus,
// types are defined, but exports are not :(
useFormState as undefined_useFormState,
useFormStatus as undefined_useFormStatus
} from "react-dom"
export const useFormState = experimental_useFormState as typeof undefined_useFormState
export const useFormStatus = experimental_useFormStatus as typeof undefined_useFormStatus |
Nice trick @neatonk 👍 BTW, I find a little odd that we have to do all sorts of workarounds in order to get things work, and it is even odder that the official docs and examples from Vercel are misleading. |
Since updating to Next.js 14, the TS runtime error persisted when importing 'experimental_useFormState':
However, the error goes away when removing 'experimental_useFormState':
We still need ''ts-ignore' otherwise get:
package.json:
|
for https://github.com/vercel/next.js/tree/canary/examples/next-forms OR |
corrected code on top of https://github.com/vercel/next.js/tree/canary/examples/next-forms the change is in react-dom type version to 18.2.14 "@types/react": "^18.2.34", "@types/react-dom": "^18.2.14", refer for detailed problem details and other work arounds suggested by NextJS auhtor and others vercel/next.js#56041
Yeah, I'd recommend just upgrading to the latest versions for the new types 😄 |
It means alot coming from the author himself to second my suggestion! Thank
you @leerob
😊
BTW, Lee, Just FYI, the latest Node v20 and Next v14 combination is not
getting compiled on AWS amplify.
…On Thu, 2 Nov, 2023, 20:03 Lee Robinson, ***@***.***> wrote:
Yeah, I'd recommend just upgrading to the latest versions for the new
types 😄
—
Reply to this email directly, view it on GitHub
<#56041 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQZ4KGZRYPFGAZ6BATA7TJLYCOVK7AVCNFSM6AAAAAA5IDRP7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJQHA2TCMZWGM>
.
You are receiving this because you commented.Message ID: <vercel/next.
***@***.***>
|
I'm running into
Just putting it out there in case it helps someone else. |
upgrading to the latest versions does not work. 👎 |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Hey folks, leaving an issue open here in case people search for this. Currently, there's a TS error you can safely ignore when importing
useFormState
. This is dependent on an upstream issue being merged: DefinitelyTyped/DefinitelyTyped#66726Example
The text was updated successfully, but these errors were encountered: