reactjsimporteslintes6-modules

How to fix import/no-named-as-default ESlint rule when you want to change the name of a default import?


I have the following warning from ESlint import plugin:

eslint - import/no-named-as-default: use default import syntax to import clearRegister.

import { default as clearRegister } from "./utils/form/clearForm";

Here I am using default as to rename my default imported function to clearRegister. This renaming works as a charm.

//clearForm.js
export default function clearForm() {
 ...
}

How can I fix this warning?


Solution

  • // Invalid
    import { default as clearRegister } from "./utils/form/clearForm";
    
    // Valid
    import clearForm from "./utils/form/clearForm";
    

    Check here: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default.md