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

173
Visualizações
Disable eslint error in jsx

I have the below JSX in one of my react-native components

        <TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
          <Image source={require('../../img/ic_warning.png')} style={{tintColor: colorThemes.Blue.red}}/>
        </TouchableOpacity>

I get the following ESLint error:

'require' is not defined. (no-undef)

I have tried adding line { // eslint-disable-line no-undef } after Image but that gives a parsing error. How can I get rid of this error just for that line.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

On your .eslintrc file:

{
    "globals":{
        "require": true
    }
}
over 4 years ago · Santiago Trujillo Relatório

0

I've read there are some jsx quirks so try separating it out:

<TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
  <Image
    source={require('../../img/ic_warning.png')} // eslint-disable-line no-undef
    style={{tintColor: colorThemes.Blue.red}}
  />
</TouchableOpacity>

Or you can define it above.

const warningImage = require('../../img/ic_warning.png'); // eslint-disable-line no-undef

....

<TouchableOpacity onPress={this.onEnableNotifications} style={{marginHorizontal: 10}}>
  <Image source={warningImage} style={{tintColor: colorThemes.Blue.red}}/>
</TouchableOpacity>

If this is a static path though, I would just define it outside the react class/function entirely, as an import.

over 4 years ago · Santiago Trujillo Relatório

0

In order to disable eslint warnings with comments inside jsx use

{ /* eslint-disable no-undef */ }
     <div>element causing warning </div>
{ /* eslint-enable no-undef */ }

A single line comment does not work:

{ /* eslint-disable-line no-undef */ }

Also see

https://github.com/eslint/eslint/issues/7030

over 4 years ago · Santiago Trujillo 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