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

103
Views
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 answers
Answer question

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 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!