Ant Design V5 - Removed Static Method Migration

Replace message.warn with message.warning. Replace notification.close with notification.destroy.

Ant Design
jscodeshift
Estimated time saving
Up to 1 minutes/occurrence
Change mode
Assistive
Applicability criteria

Ant Design >= 5.0.0

Made by
Ant Design
Ant Design

Usage →

Codemod CLI:

intalling vs code extension tooltip icon
codemod antd/5/removed-static-method-migration
copy CLI command icon

Codemod VS Code extension:

intalling vs code extension tooltip icon
vs code logo
Run in VS Code

Description

Replace message.warn with message.warning. Replace notification.close with notification.destroy.

Before

import { message, notification } from 'antd';
const App = () => {
  const [messageApi, contextHolder] = message.useMessage();
  const onClick1 = () => {
   message.warn();

  }
  const onClick2 = () => {
   messageApi.warn();
  };

  const [notificationApi] = notification.useNotification();
  const onClick3 = () => {
   notification.close();
  }
  const onClick4 = () => {
   notificationApi.close();
  };

  return <>{contextHolder}</>;
};

After

import { message, notification } from 'antd';
const App = () => {
  const [messageApi, contextHolder] = message.useMessage();
  const onClick1 = () => {
   message.warning();
  }
  const onClick2 = () => {
   messageApi.warning();
  };

  const [notificationApi] = notification.useNotification();
  const onClick3 = () => {
   notification.destroy();
  }
  const onClick4 = () => {
   notificationApi.destroy();
  };

  return <>{contextHolder}</>;
};