Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda