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

428
Vistas
How to pass boolean value from one component to another in react?

In useState default value set to false and send it to login component. But login component is not getting the value(user, setUser).

import Login from "../Routes/Login";

const useAuth = () => {
  const [user, setUser] = useState(false);
  return (
    <div>
      <Login user={user} setUser={setUser}></Login>
    </div>
  )
}
export default useAuth;

When I am clicking on Login button it's causing an error called "Uncaught TypeError: setUser is not a function". When login button is clicked I want to change the value of "user" false to true.

const Login = ({ user, setUser }) => {
  
  console.log(user);

  return (
    <div>
      <button onClick={() => { setUser(true) }}>Login</button>
    </div>
  );
}
export default Login;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I was not able to replicate the issue that you mentioned. Here is the code sandbox link below: https://codesandbox.io/s/wizardly-pine-4edci7?file=/src/App.js

The naming convention that you used for the useAuth component is incorrect. From the naming convention it seems like it is a custom hook but rather it is a component.

So, you should use the following naming convention for it UseAuth. And it works fine in the above given codesandbox link.

Additional Note: All the custom hooks in reactjs are to be prefixed with use keyword. So, I would suggest to change the name of the component from useAuth to just Auth all together.

about 4 years ago · Juan Pablo Isaza 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