我在 React+Javascript 中使用了 react-notification-system,当我在 React+Typescript 中尝试时,它会抛出错误
Type 'ReactInstance' is not assignable to type 'null'
Type 'Element' is not assignable to type 'null'
在包含的行中componentDidMount()
患者添加.tsx
import * as NotificationSystem from 'react-notification-system';
class Patientadd extends React.Component<any, IState> {
public componentDidMount=()=>{
this._notificationSystem = this.refs.notificationSystem;
}
_notificationSystem: null;
_addNotification=(event)=> {
this._notificationSystem.addNotification({
message: event.message,
title:event.title,
level: event.level,
autoDismiss: event.autoDismiss,
});
}
public render() {
return (
<div className="App2">
<NotificationSystem ref="notificationSystem" />
</div>
);
}
}