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

104
Vistas
reactjs - show dialog on all pages using a button component, wherever it is included

In my react app, I have a header with a show dialog button.
This header component is included in all pages as necessary.

My current logic to show the dialog is as follows:

  • When user clicks the button, I dispatch an action to redux store { type:SHOW_DIALOG }, and let the parent component handle the state change and draw the dialog. I am using material-UI swipeable drawer component.

Handle Click event in an iconbutton in header component...

 const handleClick = () => {
    /*
     * temporary bypass surgery to avoid going through login dialog
     * dispatch({type:'SHOW_CONTACT_INFO'})
     * return;
     */
    if (!isLoggedIn)  dispatch({type: 'SHOW_LOGIN_DLG'})
    else router.push('/my-account')
  }

In the parent page, where the header is contained...

// ...other code
   <Container>
    {/* Whether or not to show the login dialog . */}
    {loginProcessState>=1 && loginProcessState<=7
       ?<LoginDialog type={loginProcessState===1?"login":"otp"} />
       : null}
    {/* if contact edit dialog is set to show, show it. */}
    {contactEditDisplay? <ProfileEditDialog />:null}
   </Container>
  );

But, since I have many pages (around 10 pages and server side rendering with NextJS), I will have to repeat the state management in all those pages where the dialog must be shown.

Excuse my lack of knowledge here. Is it possible to avoid this dialog state check in the parent component / page. If so, how can i do it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Suggestion:

  • Move the LoginDialog component up and render it directly within the root <App/> component.

  • And then use React.useContext to call that dispatch in various components to trigger loginProcessState.

The above should help you render the Login acros all components.

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