封装react ant design 的Notification组件notification is not defined

如题:
官网Notification代码

import { Button, notification } from 'antd';

const openNotification = () => {
  notification.open({
    message: 'Notification Title',
    description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
    onClick: () => {
      console.log('Notification Clicked!');
    },
  });
};

ReactDOM.render(
  <Button type="primary" onClick={openNotification}>Open the notification box</Button>,
  mountNode
);

自己封装组件代码

import React from 'react'
import { Notification} from 'antd';

export default class Notifi extends React.Component {
    constructor(props) {
        super(props);
    }
    openNotification = () => {
        console.log(`this.props.notification:${JSON.stringify(this.props)}`)
        const {message,description} = this.props.notification
        
        notification.open({
          message: message,
          description: description,
        })
    }
    componentDidMount(){
        this.openNotification()
    }

    render(){
        return(<div></div>)
    }
}

想问下为啥报ReferenceError: notification is not defined这个错误,感觉是this问题,但是没找到合适的解决方法

阅读 4.5k
1 个回答
import { Notification} from 'antd';

你写成大写了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题