Troubleshooting: Why isn't makeStyles adding dynamic style to Material UI Menu?

I'm attempting to dynamically generate classes for the material ui Menu using the following approach :

const useStyles = (props) => {
  return makeStyles({
    paper: props.style,
  });
};

const StyledMenu = (props) => {
  const classes = useStyles(props)();
  return <Menu {...props} className={classes.paper} />;
};

render() {
const { state, fnsMenuBtn, fieldsMenuBtn, props } = this;
const { fnsMenuIsOpen, fieldsMenuIsOpen } = state;
return (
<StyledMenu
          id="fnsMenuEl"
          anchorEl={fnsMenuBtn}
          keepMounted
          open={fnsMenuIsOpen}
          style={{ border: "1px solid blue" }}
          onClose={(e) => {
            vm.setState((state, props) => {
              return {
                fnsMenuIsOpen: !state.fnsMenuIsOpen,
              };
            });
          }}
        >
          {Object.keys(formulajs).map((fnName) => (
            <MenuItem onClick={(e) => {}} key={fnName}>
              {fnName}
            </MenuItem>
          ))}
 </StyledMenu>
)
}

However, the desired style is not being applied to the menu What am I missing? Is there an alternative way to achieve this?

Answer №1

Instead of using className, it is recommended to use classes.

const CustomizedMenu = (props) => {
 const classes = useStyles(props)();
 return <Menu {...props} classes={{paper: classes.paper}} />;
};

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

How to automatically refresh a page when the URL changes with Next.js router?

On my page, users have the option to narrow down their search using filters. However, there is an issue where if a user selects a filter for "rent" or "buy", the URL does not automatically refresh to reflect the changes. Even though the changes are reflect ...

A method for consolidating multiple enum declarations in a single TypeScript file and exporting them under a single statement to avoid direct exposure of individual enums

I am looking to consolidate multiple enums in a single file and export them under one export statement. Then, when I import this unified file in another file, I should be able to access any specific enum as needed. My current setup involves having 2 separ ...

I am puzzled as to why my code in React is rendering twice without any apparent reason

I ran into a strange issue where my console.log("hi") was being displayed twice. I was working on a simple todo-list project and noticed that everything was getting double clicked. After some troubleshooting, it seems like the code is executing any JavaScr ...

Guide to deploying a React application - paths requiring adjustments

I am a novice developer looking to learn more. Recently, I decided to clone Emilio Quintanas Servitodo APP into my own repository. After downloading the repo, I attempted to use gh-pages with npm to build and deploy the APP. However, I encountered an issue ...

What causes the error when I use "use client" at the top of a component in Next.js?

Whenever I include "use client" at the top of my component, I encounter the following error: event - compiled client and server successfully in 2.5s (265 modules) wait - compiling... event - compiled client and server successfully in 932 ms (265 modules) ...

Formik's validation feature does not currently support integration with Material UI's Autocomplete component

I am looking to showcase how validation errors are displayed when a user clears their selection. https://i.stack.imgur.com/ULEgs.png For reference, here is the sandbox link: https://codesandbox.io/p/sandbox/formik-autocomplete-yh3sl7?file=%2Fsrc%2FApp.ts ...

Creating dynamic, personalized content within an AppBar

In my composition, I have a material-ui AppBar positioned at the top, structured like this: <App> <AppBar/> <Main> <Route component={FooPage}/> <Route component={BarPage}/> </Main </App> My goal is to ...

Material UI defaults remain unchanged despite any emotional influence

I'm currently experimenting with custom styling on a MaterialUI Typography component using the code snippet below: const StyledTitleTypography = styled(Typography)` color: 'black'; font-weight: 'bold'; `; <StyledTitleTypogr ...

Tips for handling a multi-step form in React?

Below is the code snippet for the multistep form I have been working on: import clsx from 'clsx'; import React from 'react'; import PropTypes from 'prop-types'; import { makeStyles, withStyles } from '@material-ui/styles ...

What is the best way to retrieve the data from this date object?

How can I access the date and time in the code below? I've attempted using functions within the Text block without success. It's unclear to me what mistake I'm making or how to correctly access this object, or transform it into an object th ...

What is the best way to set up a React handler that can handle multiple values effectively?

Struggling with a handler that is not behaving as expected. I need to update the 'quantity' value of multiple items, but currently they all get updated with the last value entered. How can I change multiple values and update items individually? H ...

Please provide TypeScript code for a React wrapper function that augments a component's props with two additional functions

During the course of my project, I implemented a function wrapping React component to incorporate undo/redo functionality using keyboard shortcuts Ctrl+Z and Shift+Ctrl+Z. Here is an example: import React from 'react'; interface WithUndoRedoProp ...

The menu is failing to open the intended div index

Hello everyone, I’m currently facing an issue with a 2-dimensional dataset. The data has a nested structure that includes links. const data = [ // First Div Panel [ { id: 1, url: "/services", title: "Services" }, { ...

Ensure the function has completed setting state before proceeding to the next function

async componentDidMount() { this.loadSelectors(); this.useSelectors(); }; loadSelectors = () => { this.setState({"Selector": "Test"}); } useSelectors = () => { console.log(this.state.Selector); } Is there a way to ensure that loadS ...

The state is not being successfully updated in another one of my functions

I'm completely new to the world of React and I'm a bit puzzled as to why my state isn't updating in another method of mine. Here's an example below: fetchMovies = () => { const self = this; axios.get("https://api.themoviedb. ...

Issues with material styling loading on the production build

I am currently working on a project using Nextjs and Material UI. The project runs smoothly in development mode, but encounters styling issues when built for production. Specifically, upon navigating to a second page, certain components like Dialog load wi ...

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

Exploring the power of colors in Tailwind CSS and Material UI for your CSS/SCSS styling

Discovering unique color palettes like the Tailwind Color for Tailwind CSS and theMaterial UI colors has been inspiring. These collections offer a range of beautifully named colors from 100 to 900 and A100 to A400, reminiscent of font styles. I am intrig ...

The styling of React-Sidenav's main content is lacking

Currently utilizing the following library: https://github.com/trendmicro-frontend/react-sidenav The Sidenav functionality is working well, but I am facing challenges in implementing the main content style. Any idea why the main content is not included in ...

Implementing Pagination in React using Material UI Framework

I am trying to implement pagination based on the length of an array, which is currently 2. Therefore, I need a total of 2 pages to display each array item per page. Can someone help me achieve this? View my solution on CodeSandbox Desired output: Page 1 ...