Skip to content

Commit ad19a55

Browse files
committed
fix: async error is not printed
This will let sentry (which is used by bilibili.com) catch the async errors.
1 parent fd18706 commit ad19a55

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/App.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ export default function App() {
1818
</div>
1919
<input
2020
placeholder='搜索评论'
21-
onKeyDown={async (e) => {
21+
onKeyDown={(e) => {
2222
if (e.key === 'Enter' && promiseRef.current) {
2323
e.preventDefault()
2424
// `e.currentTarget` will be null after `await`
2525
const keyword = e.currentTarget.value
26-
const allComments = await promiseRef.current
27-
const comments = searchComments(allComments, keyword)
28-
setComments(comments)
26+
promiseRef.current
27+
.then((allComments) => {
28+
const comments = searchComments(allComments, keyword)
29+
setComments(comments)
30+
})
31+
.catch((e) => {
32+
console.error(e)
33+
})
2934
}
3035
}}
3136
/>
@@ -54,7 +59,7 @@ const CommentTree: React.FC<CommentProps> = ({ comments, sub = false }) => {
5459
if (!comments) return null
5560
return (
5661
<ul>
57-
{comments?.map((comment) => (
62+
{comments.map((comment) => (
5863
<li
5964
key={comment.rpid}
6065
className='comment-item'

0 commit comments

Comments
 (0)