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

213
Visualizações
How can I comment out some HTML code defined into the return() method of a React component?

I am very new in ReactJS and I am facing this problem: how to comment out some HTML code defined into the render() method?

For example I have a component like this:

import React, {Component} from 'react';

class SearchBar extends Component {

    constructor(props) {
        super(props);

        this.state = { term: '' };

    }

    render() {
        //return <input onChange={this.onInputChange} /> ;
        return (
            <div>
                
                <input onChange={event => this.setState({ term: event.target.value })} />
                Value of the input: {this.state.term}
                
            </div>
        );
    }

    /*
    onInputChange(event) {
        console.log(event.target.value);

    }*/

}

export default SearchBar;

I tried to comment out a section of the html returned by the render() method in this way:

render() {
    //return <input onChange={this.onInputChange} /> ;
    return (
        <div>
            
            <!-- <input onChange={event => this.setState({ term: event.target.value })} /> -->
            <!--Value of the input: {this.state.term} -->

            <p>I want to see only this !!</p>
            
        </div>
    );
}

but it is wrong.

What am I missing? How can I comment out some HTML from here?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Do It as you would in js

<div>
{/*
<div/>

*/}

</div>
about 4 years ago · Juan Pablo Isaza Relatório

0

In JSX files you can use block comments inside of curly braces, e.g. {/* My comment */}.

In your case:

render() {
    //return <input onChange={this.onInputChange} /> ;
    return (
        <div>
            
            {/* <input onChange={event => this.setState({ term: event.target.value })} /> */}
            {/*-Value of the input: {this.state.term} */}

            <p>I want to see only this !!</p>
            
        </div>
    );
}
about 4 years ago · Juan Pablo Isaza Relatório

0

 {/* <input onChange={event => this.setState({ term: event.target.value })} /> */}
 {/*-Value of the input: {this.state.term} */}

Inside the render block, we must use the multi-line comments in curly braces {/* */}.

This is a detailed ref

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