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

161
Views
Sigo redirigiendo a '/chats' usando history.push() Intenté hacer que el usuario fuera nulo pero me quedé atascado

Estaba viendo un tutorial y me quedé atascado en esta parte en la que sigo redirigiendo a '/chat'. Establecí el usuario en nulo pero sigo redirigiendo a '/ chats'. Intenté volver a ver el video, pero sigo atascado en esta parte.

AuthContext.js

 import React, { useContext, useEffect, useState } from 'react' import { useHistory } from 'react-router-dom' import { auth } from '../firebase' const AuthContext = React.createContext() export const useAuth = () => useContext(AuthContext) export const AuthProvider = ({ children }) => { const [loading, setLoading] = useState(true) const [user, setUser] = useState(null) const history = useHistory() useEffect(() => { auth.onAuthStateChanged((user) => { setUser(user) setLoading(false) if (user) { history.push('/chats') } }) }, [user, history]) const value = { user } return ( <AuthContext.Provider value={value}> {!loading && children} </AuthContext.Provider> ) }

Aplicación.js

 import 'firebase/app' import { BrowserRouter as Router, Route, Switch } from 'react-router-dom' import Chats from './components/Chats' import Login from './components/Login' import { AuthProvider } from './context/AuthContext' function App() { return ( <> <Router> <AuthProvider> <Switch> <Route path="/chats"> <Chats /> </Route> <Route path="/"> <Login /> </Route> </Switch> </AuthProvider> </Router> </> ) } export default App
about 4 years ago · Juan Pablo Isaza
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!