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

267
Visualizações
How to always see React component event handlers in rendered HTML

Suppose we have the following simple class-based React component:

const e = React.createElement;
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            clicked: false
        };
    }
    render() {
        let sizeValue = "16px";
        if(this.state.clicked) {
            sizeValue = "28px";
        }
        return e(
            "div",
            {
                style: {fontSize: sizeValue},
                onClick: () => this.setState({
                    clicked: !this.state.clicked
                })
            },
            this.state.clicked ? 'big text' : 'small text'
        );
    }
}

const container = document.querySelector('#root');
ReactDOM.render(e(App), container);

So if someone clicks the div, its text becomes big and if clicks again, the text returns to default size.

As I see, in this case React doesn't add any attribute like onclick="..." or another to the component in rendered HTML. And if we want to learn at the front-end by some JS client custom code whether component has event handler or some logic, we need to parse JS code of the component in its JS file.

My question, is there build-in or third-party option to always see component event handlers and/or its logic in rendered HTML in some HTML attribute for example something like data-react="..." ?

I mean "to see" not "manually" by a developer, but "programmatically" by custom JS client code.

I also mean not manual adding an attribute in JS code of a component with description of its handlers or logic, but enabling an option (if there is one) so that React itself "automatically" would add such attribute in rendered HTML.

about 4 years ago · Juan Pablo Isaza
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