K
K
k34992021-10-12 01:13:10
React
k3499, 2021-10-12 01:13:10

How to remake a function in jsx so that there is no error?

A linter error appears

Expected an assignment or function call and instead saw an expression no-unused-expressions


As far as I understand it is impossible to use if in jsx, but how then to remake this function?

const handleTumblerClick = (isChecked) => {
    if (isRequestDone || isRequestInSavedDone) {
      isOnSavedPage ? filterShortFilmsInSaved(isChecked) : filterShortFilms(isChecked);
    }
  };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-10-12
@k3499

You misunderstand.
It jsxhas nothing to do with it at all.
The rule enabled by default eslint does not like when the train operator is "hanging in the air" (not assigned to a variable or not passed to a function, for example). Rewrite to if else, somehow use the result (for example return isOnSa...), or turn off\ignore the rule - there is no real problem here, it's just that such constructions can often be a mistake (when you just forgot to use the result).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question