-
Notifications
You must be signed in to change notification settings - Fork 114
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
async mediaCapabilities #52
async mediaCapabilities #52
Conversation
Thank you. I appreciate your work on this PR. |
I've just finished commenting on #51 myself to highlight potential improvements. |
@anton-karlovskiy I pushed your suggestion to this PR, if this gets traction and encoding seem needed we can easily add it then. I wonder if it would get used. |
Thank you. I appreciated your working on this PR updates. |
Would you mind checking my comments on this PR? Thank you! |
@anton-karlovskiy Also fixed the tests, they weren't blocking. And created another ticket for supporting encoding information, currently not available in chrome 👉 #54 |
Thank you @wingleung ! For #54, I'd like to ask @addyosmani first. |
media-capabilities/index.js
Outdated
.decodingInfo(mediaDecodingConfig) | ||
.then(setMediaCapabilitiesInfo) | ||
.catch(error => console.error(error)); | ||
}) |
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 wonder if this raises hook warning.
I think the logic inside useEffect
hook would be executed every re-rendering of the component with this hook inside. It would not be good for performance.
I think it could be something like the following.
useEffect(() => {
supported &&
navigator
.mediaCapabilities
.decodingInfo(mediaDecodingConfig)
.then(setMediaCapabilitiesInfo)
.catch(error => console.error(error));
}, [supported, mediaDecodingConfig]);
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 pass an empty array to have the componentDidMount
effect.
If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument.
https://reactjs.org/docs/hooks-faq.html#what-can-i-do-if-my-effect-dependencies-change-too-often
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.
Thank you @wingleung for your updating.
Yes, you're correct.
As far as I know, if then, the useEffect hook would raise warnings because dependencies like supported
and mediaDecodingConfig
are missing.
If we tried that hook in the real react project (dev env), then we could know it.
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.
If possible, would you mind adding ; at the end of useEffect hook for consistency?
Thank you @wingleung |
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.
LGTM
Thanks for working on these changes, @wingleung. Overall these look solid. There are a few minor changes we would like to make regarding Let's get this into the release. |
resolves #50