-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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] Migrate to hooks #15678
[withWidth] Migrate to hooks #15678
Conversation
I am not sure why "argos" is failing the checks, can someone advise, |
It would be nice if we could clear up first what problem you are trying to solve, how the API looks like etc. |
@eps1lon ,to answer your question see the following.
|
Lets keep the PR only for technical integration issues, for the discussions about design lets keep it in the issue tickets otherwise it spreads over 3 places. I apologize if the issue was not clearly linked in this PR |
Details of bundle changes.Comparing: 4fccafb...0e59653
|
Seems like this is based on an outdated version of the |
@jacobbogers Thanks for your time! However, did we agree on a final direction before starting the implementation? (aside from) I believe the Do we really need a useWidth hook method now that we have the
Maybe it should be published as a different package?
I agree, I don't think that it's needed. I believe we have an existing mechanism for providing a default value when rendering on the server: |
@eps1lon Thank you, yes you are correct i see in yarn.lock the version of react-docgen to be 5.0.0-beta, 6 days ago, I was using version 3.0.0. I pulled yesteday from upstream branch (this repo i forked from) but something not quite correctly merged I think. @oliviertassinari ,
the rest of the code is for mock objects, typescript decl files, and for unit testing. Yes my implementation of the mocks (only for testing purpose)
For the motivation why i wrote a Provider.., I repost my answered to @eps1lon
I can scrap the |
@jacobbogers Nice, it's the order of magnitude I was hoping for :). Yes, I think that we should the existing infrastructure instead of anticipating a problem (no custom provider). |
@jacobbogers How is it going? |
I'm continuing the effort. |
|
||
[json2mq](https://github.com/akiran/json2mq) is used to generate media query string from a JavaScript object. | ||
|
||
{{"demo": "pages/components/use-media-query/JavaScriptMedia.js", "defaultCodeOpen": true}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can come back to it in two months, we will be able to use the Google Analytics events to better answer this question: Should we have json2mq built-in?
HI Toni, sorry for being afk, had a lot to do, |
It would be great if you could review the changes :) |
Looks great @oliviertassinari , I als see how you test it all. |
function useMediaQuery(queryInput, options = {}) { | ||
const query = queryInput.replace('@media ', ''); | ||
const multiple = Array.isArray(queryInput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just seeing this since it was not obvious that any implementation changed from the PR title.
What is the use case for this? media queries already support combining multiple queries with boolean logic. This bloats the code a lot. It's nowhere documented that this doesn't support changing the number of queries provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case for this?
The use case is useWidth. I have first tried to implement it with the existing useMediaQuery.js
logic. It wasn't possible. It was making the component render x2 x card(breakpoints), so around 10 renders.
media queries already support combining multiple queries with boolean logic.
And yet, it returns a single boolean.
This bloats the code a lot.
doesn't support changing the number of queries provided.
It should be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was making the component render x2 x card(breakpoints), so around 10 renders.
Did you profile it?
And yet, it returns a single boolean
Can always use multiple hooks. No need to overload the code.
doesn't support changing the number of queries provided.
It should be supported.
It is passed as a dependency errors to hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you profile it?
The withWith() higher-order component was making his wrapped component render 10 times. The performance impact is not the only dimension to consider. The more renders, the harder debugging experience for people using this higher order component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change wasn't released yet. It's not too late to revert it if you don't feel confident with the direction. You can play with the alternative here: https://material-ui.com/components/use-media-query/#migrating-from-withwidth. Maybe if we ignore the dynamic breakpoint occurrence, and that we use an intermediary pure component to remove the redundant renders, it would work better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An interesting implementation to benchmark against: https://github.com/streamich/use-media/blob/master/src/index.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will give it a second try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find a way to deduplicate the renders.
Notice that I haven't updated the useMediaQuery
TypeScript signature nor documented the array existance. What do you of this middle ground solution? We revert the useWidth migration example so we can, later, continue iterate on this topic without being lock-in with the array behind a public API, used by people.
Since we can't use Hooks inside of a class component, can we not deprecate quote from : https://material-ui.com/customization/breakpoints/#withwidth
React hook is already stable.
|
@henrylearn2rock We had a lot of feedback asking for a HOC to still be available #14101 |
@henrylearn2rock Thanks for raising the "once stable" issue. We should update the documentation. Don't rely on it for new code. |
Hi, before I do more work, I would to know if this is kindof ok
I havent updated the docs, although i did write some unit tests using your test utils
Closes #14101