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

636
Vistas
JS & React Trying to <div> from function but it states nothing was returned from render

export function Login() {
    window.addEventListener('load', function () {
        window.FB.getLoginStatus(function (response) {
            if (!response.authResponse) {
                console.log(response);
                return (
                    <div id='flex flex-row justify-center pb-100 fb-root'>
                        <button className='btn btn-round btn-lg'>Login</button>
                    </div>
                );
            } else {
                console.log('UserLoggedIn');
                return (
                    <div id='flex flex-row justify-center pb-100 fb-root'>
                        <button className='btn btn-round btn-lg'>Logout</button>
                    </div>
                );
            }
        });
    });
}

I am having trouble returning my button that either has login or logout depending on the response. I am using the window load function to ensure my other scripts have run first.

Error Message:

"react-dom.development.js:14169 Uncaught Error: Login(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null."
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I assume that this function is supposed to be a React component. React components need to return something. Your component is not returning anything. Based on the code above, it looks like you only want to render the button once you have a login status. So firstly return null from this function outside of window.addEventListener callback function. This will make the error go away, but will not accomplish what you are trying to do. Next, add an isLoading state to the component using the useState hook which defaults to true. Then, wrap your widow.addEventListener call inside a useEffect call and instead of returning the button, change the isLoading state to false. You will probably need a second state object to hold the result of the getLoginStatus. Then your component can conditionally return either of the buttons or null depending on the state of the component.

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