Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Logout button doesn't respond when clicked in React.js

I've made a simple logout button/function that I'm almost certain that should work but it doesn't and there isn't any error either. Here's my code:

import {Link} from 'react-router-dom';
import { CredentialsContext } from '../App';
import Todos from '../Components/Todos';

export default function Welcome() {
  const [credentials, setCredentials] = useContext(CredentialsContext)
  const logout = () => {
    setCredentials(null);
  }
  return (
    <div>
        {credentials && <button onChange={logout}>Logout</button>}
        <h1>Welcome {credentials && credentials.username}</h1>
        {!credentials &&<Link to="/register">Register</Link>}
        <br/>
        {!credentials &&<Link to="/login">Login</Link>}
        {credentials && <Todos/>}
    </div>
  )
}

Any chance my backend might have something to do with it?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Just use onClick event, not onChange.

Good luck!

about 4 years ago · Santiago Trujillo Denunciar

0

<button onChange={logout}>Logout</button>

Why you are using onChange event in button?

<button onClick={logout}>Logout</button>

Use onClick event instead of onChange event.

about 4 years ago · Santiago Trujillo Denunciar

0

Try using

{credentials && <button onChange={()=>{logout}}>Logout</button>}

or {credentials && <button onClick={()=>{logout}}>Logout</button>}

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda