Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
Why the Unnecessary 'else' after 'return' (no-else-return) error

I always use the else statement. And the data from the Data.js file. Is there something I might have overlooked?

import data from './Data'

function List(props){
  const filteredData = data.filter((el) => {
    if (props.input === '') {
      return el
    } else {
      return el.text.tiLowerCase().includes(props.input)
    }
  })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

That's just what the rule requires.

Disallows return before else.

If an if block contains a return statement, the else block becomes unnecessary. Its contents can be placed outside of the block.

If you think this rule is worth following, use instead (with correct spelling)

const filteredData = data.filter((el) => {
    if (props.input === '') {
        return el
    }
    return el.text.toLowerCase().includes(props.input)
})

or even better

const filteredData = data.filter((el) => {
    return props.input === ''
        ? el
        : el.text.toLowerCase().includes(props.input)
})

If el will alwys be truthy, then it would make more sense to return true instead.

const filteredData = data.filter((el) => {
    return props.input === ''
        ? true
        : el.text.toLowerCase().includes(props.input)
})

which allows for the simplification to

const filteredData = data.filter((el) => {
    return props.input === '' || !el.text.toLowerCase().includes(props.input)
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda