Skip to content

Commit 14e6196

Browse files
committed
Add error boundary to Flight fixture
Errors in form actions are now rethrown during render (facebook#26689), so we can handle the using an error boundary.
1 parent fd3fb8e commit 14e6196

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

fixtures/flight/src/Form.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
'use client';
22

33
import * as React from 'react';
4+
import ErrorBoundary from './ErrorBoundary.js';
45

56
export default function Form({action, children}) {
67
const [isPending, setIsPending] = React.useState(false);
78

89
return (
9-
<form
10-
action={async formData => {
11-
setIsPending(true);
12-
try {
13-
const result = await action(formData);
14-
alert(result);
15-
} catch (error) {
16-
console.error(error);
17-
} finally {
18-
setIsPending(false);
19-
}
20-
}}>
21-
<input name="name" />
22-
<button>Say Hi</button>
23-
</form>
10+
<ErrorBoundary>
11+
<form
12+
action={async formData => {
13+
setIsPending(true);
14+
try {
15+
const result = await action(formData);
16+
alert(result);
17+
} finally {
18+
setIsPending(false);
19+
}
20+
}}>
21+
<input name="name" />
22+
<button>Say Hi</button>
23+
</form>
24+
</ErrorBoundary>
2425
);
2526
}

0 commit comments

Comments
 (0)