I need to add an attribute to a snackbar notification (notistack
).
Therefore I do
import { useSnackbar } from 'notistack'
const { enqueueSnackbar } = useSnackbar()
enqueueSnackbar('message', {
variant: 'success',
SnackbarProps: { 'data-testid': 'notification' } // throws ts error
})
as it is shown in the docs, but which gives me a ts error:
Object literal may only specify known properties, and ''data-testid'' does not exist in type 'HTMLAttributes<HTMLDivElement>'.
So I added this definition:
interface SnackbarProps extends React.HTMLAttributes<HTMLDivElement> {
'data-testid'?: string
}
const { enqueueSnackbar } = useSnackbar()
enqueueSnackbar('message', {
variant: 'success',
SnackbarProps: {
'data-testid': 'notification'
} as SnackbarProps
})
It works, but I would have to add this to every file and every line, where I’m using the notification.
Is it possible to do this definition in general?