-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[withWidth] Remove the API #17350
Comments
@Bouncue You can find more detail on this topic under #14101. To sum up the discussion, the most likely path forward is to remove
We will support class components as long as React do so. Note that moving a hook to a higher-order component is relatively straightforward: import useMediaQuery from '@material-ui/core/useMediaQuery';
const withMediaQuery = (...args) => Component => props => {
const mediaQuery = useMediaQuery(...args);
return <Component mediaQuery={mediaQuery} {...props} />;
}
export default withMediaQuery; Does it help?
I can't find any demo on the drawer page that uses this API. Where did you spot it? We should remove it. |
Thanks I'll try it.
In Responsive Drawer, the
As far as I understand the component uses
|
@Bouncue Thanks for highlighting this issue, the Hidden component is no longer using withWidth, it was migrated to useMediaQuery some time ago. We will need to solve this inconsistency. |
I have a question for this. As far as I understand, built-in react hooks are not meant to be used with class components. Will |
@tlenex If there is enough request, we can make either:
const withMediaQuery("(prefers-color-scheme: dark)")(MyComponent);
<MediaQuery query="(prefers-color-scheme: dark)">
{(matches) => matches}
</MediaQuery> |
Thank you. I'd like to vote for support of both react component formats. Pretty please! Personally, I like to use class components for business logic (controllers/containers) and functional components for visualizations. My point is that sometimes business logic can depend on media queries - in that case material-ui will force me to rewrite classes to functions. More over, react team does not plan to deprecate class components as far as I know. |
This is just my opinion, but you wouldn't need to rewrite class components to function components - you could just define a function component wrapper that uses the |
What are some use cases for knowing the current breakpoint other than our internal usage in |
What do you mean by "these issues"? From what I understand:
|
So if #17350 and #23885 are different issues, why did you bring up #23885 here? These are either coupled or they're not.
I'm asking what is supposed to be migrated. How is this function used (I'm not interested in internal usage since that is separate from a public API)? |
@eps1lon The objective was to raise awareness of the potential dependency between the two issues. Considering the problem holistically could yield a better solution. #23885 might need #17350 to be fixed first. Regarding this issue and the core problem we might solve for developers. So far, I have seen 3 prior-art with the useBreakpoint (same as useWidth):
We have been deprecating A new proposal for the course of action:
cc @mui-org/core |
Done in #26136 by @m4theushw |
The docs says:
withWidth()
Will this really happen? when and in what version?
I have many class components which mean cannot use
useMediaQuery
hook. But I really need to keep watch on screen size changes.Also if Material-UI decides to get rid of
withWidth()
then why still use it in the demo? as in Responsive DrawerThis makes me confuse unsure to decide, should I just use
withWidth()
in my class components or should I convert them into functional component -which means a lot of work- to useuseMediaQuery
.Does Material-UI plans to drop support for the class component?
The text was updated successfully, but these errors were encountered: