-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathErrorBar.tsx
More file actions
35 lines (31 loc) · 931 Bytes
/
ErrorBar.tsx
File metadata and controls
35 lines (31 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useState } from 'react'
import { useConfig } from '../hooks/useConfig.js'
import { cn } from '../lib/utils.js'
import styles from '../styles/ErrorBar.module.css'
interface ErrorBarProps {
error?: Error
}
export default function ErrorBar({ error }: ErrorBarProps) {
const [showError, setShowError] = useState(error !== undefined)
const [prevError, setPrevError] = useState(error)
const { customClass } = useConfig()
if (error) console.error(error)
/// Reset error visibility when error prop changes
if (error !== prevError) {
setPrevError(error)
setShowError(error !== undefined)
}
return <div
className={cn(styles.errorBar, customClass?.errorBar)}
data-visible={showError}
>
<div>
<span>{error?.toString()}</span>
<button
aria-label='Close error message'
onClick={() => { setShowError(false) }}>
×
</button>
</div>
</div>
}