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

141
Visualizações
Warning:Invalid value for prop `data-callback` on <div> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM

In the second last div tag with id = "g_id_onload" if i assign a function to the attribute data-callback, react gives a warning:

Warning:Invalid value for prop data-callback on div tag. Either remove it from the element, or pass a string or number value to keep it in the DOM

Also data-callback never gets called. Does anyone know what is wrong with this.

class Login extends React.Component{

  handleCredentialResponse = (response)=>{
    console.log(response.credentials);
  }


  render(){
    return (
      <div className="login">
        <div className="text-center mb-2">
          <img src="http://placehold.it/60" alt="Sign in"/>
          </div>
        <form>
          <div className="text-center h3 mb-3">Sign in</div>
          <div className="mb-3">
            <label className="form-label">Email address</label>
            <input type="email" className="form-control" />
          </div>
          <div className="mb-3">
            <label className="form-label">Password</label>
            <input type="password" className="form-control"/>
          </div>
          <div className="text-center mb-3">
            <button type="submit" className="btn btn-primary">Sign in</button>
          </div>
        </form>
        <div className="mb-3 text-center form-text div_or">Or</div>
        <div className="google_signin_row">
          <div className="google_signin_col">
            <div id="g_id_onload"
              data-client_id="CLIENT_ID"
              data-callback={(res)=>this.handleCredentialResponse(res)}>
            </div>
            <div className="g_id_signin" data-type="standard" data-theme="filled_blue" data-width="250"></div>
          </div>
        </div>
      </div>
    );
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Found the solution here: https://github.com/google/recaptcha/issues/74

summary:

The data-callback attribute expects a string that defines the name of the function in the global namespace that should be fired. You cannot define the function within the attribute.

So defining the function handleCredentialResponse in global namespace and putting data-callback = "handleCredentialResponse" works.

alternative way:

class Login extends React.Component{
    constructor(props) {
        super(props);
        window.handleCredentialResponse = this.handleCredentialResponse;
    }

    handleCredentialResponse(response){
        console.log(response);
    }

    render(){
        return <div className="g_id_onload" 
            data-callback="handleCredentialResponse" 
            />
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You cannot pass a function to a custom data attribute. Try using an event handler such as onClick, onSubmit, onChange etc.

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