Calculate values dynamically when styling material-UI components

Utilizing the Material-UI style to define the class.

Now, I aim to adjust the height based on the browser's width.

Is there a way to dynamically calculate this within makeStyles() or implement a workaround?

This snippet below represents what I am trying to achieve.

const useStyles = makeStyles({
 videoContainer:{
    height: this.width / 16 * 9 // dynamically calculate height
  }
}

const Info = (props) => {
  const classes = useStyles();
  const { ...rest } = props;
  return (
    
    <div class={classes.videoContainer}>
    <video src={require("assets/180226.mp4")} 
        autoPlay muted loop>
    </video>
    </div>
  );
}

Answer №1

A dynamic height can be set within makeStyles()

const useStyles = makeStyles({
 videoContainer:{
    height: window.innerWidth / 16 * 9 // calculation for dynamic height
  }
}

Alternatively, a variable can be declared at the start and utilized within makeStyles()

const ht = window.innerHeight // perform necessary calculations
const useStyles = makeStyles({
 videoContainer:{
    height: `${ht}`
  }
}

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

Tips for creating a checkbox within a form control or form control label without using a label

Below is the code snippet that showcases my progress so far: <FormGroup> <FormControlLabel control={ <Checkbox checked={isItemSelected} onChange={(event) => handleClick(event, id)} ...

Combine two CSS effects in succession using Jquery

I am attempting to combine two CSS transition effects together. The first code snippet works well with 'animate': $('.txt').css({'transition': 'transform .5s ease-in-out ', 'transform': 'translate(3 ...

React Autocomplete Component Issue with Value Updating in Material UI

I recently developed a custom Autocomplete component in React with the help of Material UI's Autocomplete feature. Check out the code snippet below: import { useState } from "react"; import { Autocomplete as MuiAutcomplete } from "@mui/ ...

Exploring the Functionality of InputRef in Material UI Core Version 3.9.2

Encountering an issue in Material ui core version 3.9.2 When using inputRef={input => { this.input = input; }} An error is displayed: TypeError: Cannot set property 'input' of undefined If we replace this.i ...

How can you hide specific elements in HTML/CSS based on window size without relying on media queries?

How can I create an HTML/CSS toolbar where specific elements disappear completely when the browser size is decreased, similar to how the favorites bar functions in most browsers? The toolbar should be able to display a varying number of items. In this cas ...

The JSX component cannot be utilized as `ToastContainer`

Check out this Code: import axios from "axios"; import React, { useState, useEffect } from "react"; import { ToastContainer, toast } from "react-toastify"; import loaderIcon from "../../assets/images/loader.gif"; imp ...

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

Can you explain the significance of the "table$aria-label" and "input$autocomplete" attributes in the context of Svelte SMUI?

As a newcomer to Svelte and SMUI, I recently explored the official documentation at . I encountered some peculiar attribute declarations like "table$aria-label" and "input$autocomplete". The usage of dollar signs in naming conventions as well as the prefix ...

What is the best way to invoke a function only once in typescript?

Struggling to implement TypeScript in React Native for fetching an API on screen load? I've been facing a tough time with it, especially when trying to call the function only once without using timeouts. Here's my current approach, but it's ...

What is the best way to combine flex-direction and flex-wrap in one row?

I'm working with a React component that looks like this: <Card className='form-margin width card' zDepth='3'> <CardText> <strong>Test</strong><br /> This is some text </Card ...

Can you use "or" or "not" syntax with CSS input type selectors?

In the world of programming, if they actually exist, Suppose I have created an HTML form with the following input fields: <input type="text" /> <input type="password" /> <input type="checkbox" /> I wish to style all input fields that a ...

Enhancing Security: Implementing Node.js API Authentication

Looking for guidance on setting up multiple authentications with different roles in Next.js development. Can anyone help me navigate this aspect of website building? Using Next.js for the frontend Utilizing Node.js and JWT (JSON web token) for the backend ...

sending the properties from the menu component to the dish details

Having trouble with a react.js app I'm working on that involves rendering dish cards. The dish object is always null when passed as props from MenuComponent to DishDetail, resulting in nothing being displayed on the screen. Can someone please assist m ...

Role-based dynamic layout

I am currently working on a website that requires user login functionality. To achieve this, I am utilizing materialise-css and Angularjs for the front-end development, while the back-end is powered by Java-Hibernate (as Spring is not an option in my case) ...

Issue with SVG mask not functioning when transform is applied

I am struggling to apply a mask to a transformed SVG element. When I try to do this with a path, the structure is the same. If I apply the mask to an element outside of the transformed group, it works as expected. However, if I try to do the same inside, t ...

Is it feasible to incorporate a third-party JavaScript file into a React application?

I have a JavaScript file from a previous MVC project that generates a basic table using ExtJS. Currently, I'm working on developing a new React application with a navigation bar and sidebar. My goal is to explore the possibility of importing the exis ...

React Table fails to dynamically update when there is a change in the array that is

Here's the code snippet I'm currently working with: const Registration = props => { const [data, setData] = useState(props.mainData) const [order, setOrder] = useState("asc") const SortHeader = (header) => { if (order ...

Unable to serve as a JSX component. The return type 'void' is not a permissible JSX element

After creating a component called 'FormField' to streamline the code and eliminate repetition, I encountered this error message: 'FormField' cannot be used as a JSX component. Its return type 'void' is not a valid JSX element. ...

"Adjusting the position of the Icon in the Material UI ItemList to make it closer

How can I bring this icon closer to the text? I'm not sure how to do it. When I enter developer mode, it shows me this. https://i.stack.imgur.com/WzhB1.png I am uncertain about what the purplish stuff indicates. My objective is to move the icon to t ...

Why Am I Still Getting a 431 (Request Header Fields Too Large) Error in My React App Despite Clearing

Whenever I try to run a post request in my React app, I encounter the "431 (Request Header Fields Too Large)" error and I'm unable to identify the cause. Is there anyone who can assist me with this problem? I've attempted various solutions based ...