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

Chapter 13: Adding return { message: string } breaks build due to invalid typing #953

Closed
riceboyler opened this issue Dec 16, 2024 · 2 comments

Comments

@riceboyler
Copy link

riceboyler commented Dec 16, 2024

According to the types as defined in FormHTMLAttributes (in react/index.d.ts), the action property ((formData: FormData) => can only either return a void or a Promise<void>. By adding a return object as indicated in the "Reveal the Solution" sections, it breaks next build because the typing is invalid.

I believe these actions are expecting not to actually return anything, hence the errors. I had to change my code to instead throw a new Error and console.error rather than returning { message: 'Whatever message to return here' } in order to fix my builds.

I don't know if this is something that changed as of React v19.0 stable or not, but returning an object appears to no longer be supported.

image

@riceboyler
Copy link
Author

Digging further into Chapter 14, I think the issue is that the addition of the {message: string} response is being added too early. Once you start using useActionState, then the expected response changes to be able to accept a response object from the form actions.

@leerob
Copy link
Member

leerob commented Jan 15, 2025

Thank you! I will fix this

@leerob leerob closed this as completed Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants