mui / mui/material-ui

Best practice of setting props depending on breakpoints

Open
#29,333 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

discussion scope: all components
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Discussed in https://github.com/mui-org/material-ui/discussions/29318

Originally posted by mwskwong October 27, 2021
For example, I want to display a Button and set fullWidth={true} while displaying in mobile devices (i.e. smDown) and false if otherwise. I can think of two ways to implement it.

  1. Use useMediaQuery. The pros are the code will be more elegant, while the issue is it doesn't work very well with SSR. Youn will notice a layout shift in certain cases.

  2. Mount two Button, one with fullWidth set to true and the other one set to false, and then set the CSS attribute display depending on the breakpoint. The pros are it supports SSR very well., While the cons are you have to duplicate the component, which is not so great for performance and SEO.

Now the question is, which one do you prefer? Or are there better ways to achieve this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked discussion and compare the two approaches described: useMediaQuery with SSR versus mounting two Button components with breakpoint-based display. Determine whether the desired outcome is a documented recommendation or a new responsive API, then define acceptance criteria for the chosen approach and its SSR behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.