Skip to content

Commit

Permalink
can remove the action, method, and encType
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed May 6, 2024
1 parent cfdb804 commit 9a5dc7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions exercises/07.forms/04.problem.submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ function App() {
return (
<form
action="api/onboarding"
// 🐨 set the method to "POST"
// 🐨 set the encType to "multipart/form-data"
// 🐨 add an onSubmit handler that calls event.preventDefault()
// 🐨 create a FormData object from the the form (πŸ’° event.currentTarget)
// 🐨 log the result of Object.fromEntries(formData)
// πŸ¦‰ Follow these instructions in order. Test the behavior after each step
// 1️⃣ 🐨 set the method to "POST"
// 2️⃣ 🐨 set the encType to "multipart/form-data"
// 3️⃣ 🐨 add an onSubmit handler that calls event.preventDefault()
// 4️⃣ 🐨 create a FormData object from the the form (πŸ’° event.currentTarget)
// 5️⃣ 🐨 log the result of Object.fromEntries(formData)
// 6️⃣ πŸ’― as extra credit, see what happens if you remove the action, method, and encType
>
<div>
<label htmlFor="usernameInput">Username:</label>
Expand Down
4 changes: 4 additions & 0 deletions exercises/07.forms/04.solution.submit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { createRoot } from 'react-dom/client'
function App() {
return (
<form
// πŸ¦‰ note because our onSubmit calls preventDefault, the action, method,
// and encType are no longer necessary and can be removed. But we'll keep
// them around here for the exercise diff.
action="api/onboarding"
method="POST"
encType="multipart/form-data"
// πŸ¦‰ by the end of the exercise, this is all you'll actually need:
onSubmit={event => {
event.preventDefault()
const formData = new FormData(event.currentTarget)
Expand Down

0 comments on commit 9a5dc7c

Please sign in to comment.