How can I get rid of the warning import/no-anonymous-default-export in React?

YoungDad

I get the warning in the consle:"Assign object to a variable before exporting as module default import/no-anonymous-default-export."

This is coming from my .js functions which export several functions as default. I am not sure how to get rid of, while still being able to export several functions as default and keep the code simple as per below.

function init() {}

function log(error) {
  console.error(error);
}

export default {
  init,
  log,
};
 

I could write the file as:

export default function init() {}

export function log(error) {
  console.error(error);
}

Is there a setting I need to change, something I can do about it?

CertainPerformance

It's telling you to give the object being exported a name before exporting, to make it more likely that the name used is consistent throughout the codebase. For example, change to:

function init() {}

function log(error) {
  console.error(error);
}

const logger = {
  init,
  log,
};
export default logger;

(Give it whatever name makes most sense in context - logger is just an example)

But if you're going to export multiple things, using named exports would make a bit more sense IMO. Another option is to do:

export function init() {}

export function log(error) {
  console.error(error);
}

and then import them as:

import { init, log } from './foo.js';

Эта статья взята из Интернета, укажите источник при перепечатке.

Если есть какие-либо нарушения, пожалуйста, свяжитесь с[email protected] Удалить.

Отредактировано в
0

я говорю два предложения

0обзор
Войти в системуУчаствуйте в комментариях

Статьи по теме

How to get rid of Incremental annotation processing requested warning?

How can I solve the warning DEPMOD

How can I get OS default apps in android

How can I get rid of keycloak's default login page and use my own login page

How can I suppress "The tag <some-tag> is unrecognized in this browser" warning in React?

Adding proptypes to unnamed anonymous default exported functions - e.i "export default () =>{}"

Adding proptypes to unnamed anonymous default exported functions - e.i "export default () =>{}"

How to get rid of the default background of the Android DatePickerDialog in Android 4.4.4?

How can I get pagination work on Meteor 1.5.2 with react?

How can I export a variable to another file React

How can I get the absolute image path in react-native?

How to get rid of : Warning: Invalid value for prop `settaskstatus` on <span> tag

Get rid of "duplicate label" warning in Sphinx

How to get rid of warning "Calling 'BuildServiceProvider' from application code..."

How can I get rid of having to prefix a WHERE query with 'N' for Unicode strings?

How can I export the summary data in R?

How do I get rid of right margin in React?

How do I get rid of horizontal split in dwm

How do I get rid of the extra space on the Dropdown menu?

How can I get rid of "|" between navbar links?

Alamofire prints "Optional(data)", how can I get rid of "Optional"

How to get rid of a commit?

Where do these spaces come from and how can I get rid of them?

How can I get this React/Redux app to render properly?

How do I get rid of extra BottomAppBar in Flutter?

How do I get rid of None values in list? Python

How can I get rid of whitespace on the right side of my page?

Is there a way to get rid of css with react?

How can I get rid of these white borders around my carousel?

TOP список

  1. 1

    Распределение Рэлея Curve_fit на Python

  2. 2

    Merging legends in plotly subplot

  3. 3

    В типе Observable <unknown> отсутствуют следующие свойства из типа Promise <any>.

  4. 4

    TypeError: store.getState não é uma função. (Em 'store.getState ()', 'store.getState' é indefinido, como posso resolver esse problema?

  5. 5

    Как в точности работает внутренний пул потоков Nodejs?

  6. 6

    ViewPager2 мигает / перезагружается при смахивании

  7. 7

    How do I search for an entry out of two SQL tables and know which table it came from?

  8. 8

    Как я могу нарисовать заполненный прямоугольник в JFreeChart?

  9. 9

    Невозможно запустить iReports 5.6.0 с Netbeans 8 и JDK 1.8

  10. 10

    Как добавить заголовок в легенду для двух независимых групп, состоящих из трех подгрупп?

  11. 11

    Камунда - Фильтровать список задач по назначенной группе

  12. 12

    Проверьте, была ли новая вкладка открыта с помощью puppeteer

  13. 13

    JavaFX TextArea как установить текст с автоматическим переносом новой строки

  14. 14

    Как запустить скрипт node js из скрипта powershell и использовать вывод скрипта node js в скрипте powershell?

  15. 15

    Элемент "эллипс", созданный с помощью JS, не отображается в HTML

  16. 16

    Два ArrayList один адаптер RecyclerView

  17. 17

    Ошибка при использовании CONVERT при выборе из OPENJSON

  18. 18

    Как перезапустить приложение JavaFX при нажатии кнопки

  19. 19

    невозможно соединить intelliJ с Docker Machine

  20. 20

    Невозможно понять дерево вызовов jprofiler

  21. 21

    Slick Carousel + Проблема форматирования аккордеона

популярныйтег

файл