Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
El botón de cierre de sesión no responde cuando se hace clic en React.js

He creado un botón/función de cierre de sesión simple que estoy casi seguro de que debería funcionar, pero no funciona y tampoco hay ningún error. Aquí está mi código:

 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> ) }

¿Alguna posibilidad de que mi backend tenga algo que ver con eso?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Simplemente use el evento onClick , no onChange .

¡Buena suerte!

about 4 years ago · Santiago Trujillo Report

0

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

¿Por qué está utilizando el evento onChange en el botón?

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

Use el evento onClick en lugar del evento onChange.

about 4 years ago · Santiago Trujillo Report

0

Intenta usar

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

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

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!