The Drawer functionality is not working properly upon the initial rendering from the Server Side Render

I'm currently facing challenges in my Meteor app while trying to incorporate SSR and using the Drawer component from MaterialUI with an onClick event handler.

If anyone has any boilerplate or examples that could help, I would greatly appreciate it.

Here are the versions I am using:

@material-ui/core: 3.1.1

@material-ui/icons: 3.0.1

[email protected]

This is how I have implemented the Drawer so far:

  const Header = props => {
  const { classes, handleDrawerToggle, mobileOpen } = props

  return (
    <div>
      <StyledAppBar>
        <TopBorders>
          <div />
          <div />
          <div />
          <div />
        </TopBorders>
        <Grid container justify="center">
          <Grid item lg={9} md={10} sm={9} xs={12}>
            <Toolbar>
              <div style={{ flex: 1 }}>
                <Link to="/">
                  <LogoImage src="/img/Logo.png" alt="Drone Pilot" />
                </Link>
              </div>
              <div>
                <Hidden mdUp implementation="css">
                  <IconButton
                    aria-label="open drawer"
                    onClick={() => handleDrawerToggle(!mobileOpen)}
                  >
                    <MenuIcon />
                  </IconButton>
                </Hidden>
                <Hidden smDown implementation="css">
                  <NavItem />
                </Hidden>
              </div>
            </Toolbar>
          </Grid>
        </Grid>
      </StyledAppBar>
      <Drawer
        variant="temporary"
        anchor="right"
        open={mobileOpen}
        onClose={() => handleDrawerToggle()}
        ModalProps={{
          keepMounted: true, // Better open performance on mobile.
        }}
        classes={{
          paper: classes.drawerPaper,
        }}
      >
        <NavItem />
      </Drawer>
    </div>
  )
}

const mapStateToProps = state => ({
  mobileOpen: state.mainReducer.mobileOpen,
})

function mapDispatchToProps(dispatch) {
  return bindActionCreators(ActionCreators, dispatch)
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(withStyles(styles)(Header))

Answer №1

The functionality of the drawer is controlled by toggling state, triggered by event handlers. These event handlers are not included in the server-side rendered content. This is the expected behavior of React, where events are only attached once the client side takes over.

Reference:

When using ReactDOM.hydrate() on a node that already contains server-rendered markup, React will preserve it and only add event handlers. This allows for a highly performant first-load experience.

React Docs

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is causing styled-components to include my attributes in the DOM?

In various parts of my code, there is a snippet like this: import React from 'react' import styled from 'styled-components' type PropsType = { direction?: 'horizontal' | 'vertical' flex?: number | string width ...

Exploring the mern.io scaffolder tool - Unraveling the essence of the .need method

While exploring the code of the scaffolder mern.io, I came across an intriguing method called ".need". It appeared to be related to es6 classes, but unfortunately, I couldn't find any valuable information about it. Thus, I'm curious to know: what ...

What steps should be taken to proceed with the mounting process once the condition is

I am currently developing a React application and I have an implementation of componentWillMount that is structured as follows: componentWillMount() { axios.get('/user').then(response => { console.log(response.data.user) if (respons ...

Removing scrollbar from table in React using Material UI

I successfully created a basic table using react and material UI by following the instructions found at: https://material-ui.com/components/tables/#table. The table is functioning properly, but I am finding the scrollbar to be a bit inconvenient. https:// ...

What is the reason behind Meteor automatically updating a record without the need to run a "Meteor.call" function for an update?

I am currently developing a Meteor.js application and while I have grasped the basic concepts of Meteor, I feel like I might be missing something when it comes to its reactivity principles. Using angular-meteor, I am utilizing a $scope variable in my view ...

React/Redux Web Applications Hosting (front-end)

I'm grappling with something at the moment. Consider a scenario where I have developed a website or single-page application using React/Redux. Let's assume that there are no API calls involved, meaning it's solely focused on the front-end as ...

How can one incorporate additional color options into Material-UI beyond just Primary and Secondary?

I've searched high and low, combed through documentation, scoured YouTube for tutorials, and Googled endlessly with no luck. It feels like this might be beyond the capabilities of MUI, but it's becoming quite frustrating. All I want is a clean a ...

The Next.js Image component is not compatible with an external URL as the image source

I've been struggling to use the image component in Next.js with an external URL as the source, but I keep encountering an error. I followed the instructions in the official Next.js documentation and updated the next.config.js file, but unfortunately, ...

Using React to visualize data from Node.js in Chart.js

My Node.js application fetches a JSON object from a MySQL database and I want to display it in real-time using Chart.js and React. Here is the code snippet for fetching the JSON data from the MySQL database (script.js): const mysql=require('mysql&apo ...

Using custom input with Formik in React: A comprehensive guide

Currently, I am attempting to integrate the DatePicker component into Formik. However, upon clicking on a date in the DatePicker, the form value does not get updated. Instead, an error occurs: Uncaught TypeError: e.persist is not a function at Formik. ...

`How to prevent Query parameters from being lost upon reloading in Nextjs Router while maintaining a clean URL structure?`

My challenge lies in sending data via router.push to a page with dynamic room id (src/pages/editor/[roomid].tsx) in Next.js. I want the URL to stay clean so users can easily edit their username in the URL if needed. When initially loaded, router.query suc ...

What is the best way to extract parameters from MERN routing?

Recently, I've been facing difficulties while trying to retrieve data from MongoDB using dynamic routing. The URL structure is as follows: http://localhost:3000/paprogram/:_id` http://localhost:3000/paprogram/60bfbf12f8d33aef9ae4ebb9` I am attempting ...

Equal size images displayed within cards in Material UI

Is there a way to create a list of Material UI components with images that have uniform height, even if the original images vary in size? I want to make all image heights responsive and consistent across all cards. Any suggestions on how to achieve this? ...

Issue with React Testing Library not reflecting changes in input field state

Recently delving into RLT, I encountered a strange issue while attempting to write a unit test for an input box. The RTL does not seem to update the state for the input value correctly. Below is the code snippet I used for testing: import { fireEvent, scre ...

Having trouble importing Bootstrap into Next.js? It seems like the issue may be related to the

I am currently facing an issue with importing bootstrap 5.3.2 (not react-bootstrap) into my NextJS 14.1.0 project that utilizes the new App Router. My goal is to strategically utilize individual Bootstrap components (not through data-attrs). I managed to ...

What is the proper placement for index.html <head/> class helper functions within a ReactJS Component?

My custom helper functions are stored in a JavaScript file called classie.js: ( function( window ) { 'use strict'; function classReg( className ) { return new RegExp("(^|\\s+)" + className + "(\\s+|$)"); } var hasClass, ...

Tips for resolving the issue: Notification: incorrect value assigned to the `settaskstatus` property within the <span> element

After creating my own component as shown below: import React, { Component, Fragment } from 'react'; import Checkbox from '@material-ui/core/Checkbox'; import clsx from 'clsx'; import { makeStyles } from '@material-ui/cor ...

Implement real-time updates on the React frontend application by utilizing the state hook in React.js to dynamically

While I was making changes to my code in order to ensure that the update request works smoothly without refreshing the react frontend, things didn't go according to plan. Here's where I currently stand: On the "Profile" component page, I created ...

How to set the color of the active button within a group of buttons in React using Material UI

I'm having trouble changing the color of a button that is clicked in Material UI. The first button should be active by default. However, I can't use e.target.name because there is no name attribute in the span created within the Button component. ...

Is there a way to access a component's props within the getServerSideProps() method?

Is there a way to pass parameters to a React component and then access the values of those parameters within the getServerSideProps function of the component? I am utilizing the next framework in React JS. <Menu name={menuName} /> In this example, ...