@@ -125,8 +125,15 @@ export const action = async ({ request }: ActionArgs) => {
125
125
} ;
126
126
127
127
export default function Register ( ) {
128
- const actionData = useActionData < typeof action > ( ) || { } ;
129
- const { fieldErrors, fields, formError } = actionData ;
128
+ const actionData = useActionData < typeof action > ( ) ;
129
+ let fieldErrors =
130
+ actionData && "fieldErrors" in actionData
131
+ ? actionData . fieldErrors
132
+ : undefined ;
133
+ let formError =
134
+ actionData && "formError" in actionData ? actionData . formError : undefined ;
135
+ let fields =
136
+ actionData && "fields" in actionData ? actionData . fields : undefined ;
130
137
const [ searchParams ] = useSearchParams ( ) ;
131
138
132
139
React . useEffect ( ( ) => {
@@ -169,7 +176,7 @@ export default function Register() {
169
176
id = "form-error-text"
170
177
role = "alert"
171
178
>
172
- { actionData . formError }
179
+ { formError }
173
180
</ span >
174
181
</ div >
175
182
) : null }
@@ -194,7 +201,7 @@ export default function Register() {
194
201
error = { fieldErrors ?. nameFirst }
195
202
>
196
203
< Label > First Name</ Label >
197
- < Field defaultValue = { fields ?. nameFirst } />
204
+ < Field defaultValue = { fields ?. nameFirst || undefined } />
198
205
< FieldError />
199
206
</ FieldProvider >
200
207
< FieldProvider
@@ -203,7 +210,7 @@ export default function Register() {
203
210
error = { fieldErrors ?. nameLast }
204
211
>
205
212
< Label > Last Name</ Label >
206
- < Field defaultValue = { fields ?. nameLast } />
213
+ < Field defaultValue = { fields ?. nameLast || undefined } />
207
214
< FieldError />
208
215
</ FieldProvider >
209
216
< FieldProvider
@@ -216,7 +223,7 @@ export default function Register() {
216
223
< Field
217
224
type = "email"
218
225
219
- defaultValue = { fields ?. email }
226
+ defaultValue = { fields ?. email || undefined }
220
227
/>
221
228
< FieldError />
222
229
</ FieldProvider >
@@ -227,7 +234,10 @@ export default function Register() {
227
234
error = { fieldErrors ?. password }
228
235
>
229
236
< Label > Password</ Label >
230
- < Field type = "password" defaultValue = { fields ?. password } />
237
+ < Field
238
+ type = "password"
239
+ defaultValue = { fields ?. password || undefined }
240
+ />
231
241
< FieldError />
232
242
</ FieldProvider >
233
243
< Button className = "register__email-submit-button" > Sign Up</ Button >
0 commit comments