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

128
Visualizações
onClick in button tag is not working in react component

hi i am a newbie in react i am facing a issue in classbased component given below is my component which i am calling inside another component of react i just want to call the temp function when onClick gets fired but in my case it is not working please let me know where i am doing wrong?

import react from 'react'
import '../../../css/classBased/editor/textFieldForEditor.css'
import addTextField from './leftTrayIconsForEditor'
class TextField extends react.Component {
    
    temp() {
        console.log('hi there')
    }
    render(){
        return (
            <div className='textfield_parent_container'>
          <div>
          <center>
          <div>
          <button onClick={()=> {this.temp()}}>
          <i className="material-icons md-18">article</i>
          </button>
          <button>
          <i className="material-icons md-18">image</i>
          </button>
          <button>
          <i className="material-icons md-18">movie</i>
          </button>
          </div>
          </center>
          </div>
          <textarea className='text' id={`textfield${this.props.widgetNumber}`}></textarea>
          <div className='utilitytrayouter'>
          <center>
          <div className='temp'>
          <button>
          <i className="material-icons md-18">article</i>
          </button>
          <button>
          <i className="material-icons md-18">image</i>
          </button>
          <button>
          <i className="material-icons md-18">movie</i>
          </button>
          </div>
          </center>
          </div>
          </div>
        )
    }
}
export default TextField;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It actually works and clicking the first article button really calls console.log('hi there'). Proving the error message could be helpful.

But since you are using Class components most likely you are facing the Handling Events "problem" and what you need is to bind your temp method to TextField component. The easiest way (but may require a Babel plugin depending on your setup) is by using the arrow function:

temp = () => {console.log('hi there')}
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