News for hackers. Stuff that matters.
Re:YouTube Video as Background in React by ht85 on Sunday March 27, 2022 @05:31AM (#30818956)
Not trying to be rude, I am genuinely curious how a niche, low quality project like this is the 11th post on HN?
Re:YouTube Video as Background in React by sph on Sunday March 27, 2022 @05:36AM (#30818977)
Simple, because of HN's algorithm and population at this time of day. It probably got, due to pure random chance, a couple votes in quick succession, something which is rare at the start of the day, so it got promoted to the front page in case it's a smashing piece of news.

It'll decay over time, but sometimes this has the adverse effect of promoting not-as-interesting posts just because they had a chance of a spot on the front page, attracting more upvotes, while many very interesting articles never got enough time to be upvoted and are lost.

I quite like HN's algorithm, but this is one major flaw of upvote-based systems.

Re:YouTube Video as Background in React by izietto on Sunday March 27, 2022 @05:47AM (#30819021)
Why low quality?
Re:YouTube Video as Background in React by ht85 on Sunday March 27, 2022 @06:53AM (#30819291)
- no documentation, not even a few lines

- no example without cloning

- example provided doesn't run without modifying it (empty video url)

- no tests

- doesn't look maintained (e.g. 3 years old typescript version)

Then looking at index.tsx

- using Class as component (debatable but really not idiomatic anymore)

- weird empty lines and spaces

- weird `this.container` pattern, not to mention the type of it is unsafe

- `aspectRatio` has to be in `x:y` format (including the colon), no way to know that unless you read the code in depth (also weird choice)

- using the anti-pattern of setting derived state (aspectRatio) in this.state, rendering again with a different aspect ratio won't work

- componentWillUnmount does not remove the listener, as calling `.bind` there will create a function that doesn't match the one in componentDidMount

- using `.bind` inline insted of using fat arrows directly when creating class methods

- the weird syntax for `playerProps =`

- hard coding some of the `PlayerVars` props instead of just makin props `PlayerVars & { ... }` to allow passing any props supported by react-youtube

Anyway that's just at a glance, I'm sure cloning the project and trying to use it would reveal a lot more.

Re:YouTube Video as Background in React by Jamie9912 on Sunday March 27, 2022 @05:59AM (#30819058)
46k lines of code for this
Re:YouTube Video as Background in React by izietto on Sunday March 27, 2022 @06:20AM (#30819146)
If I should point to something that isn't very good is the placeholder test, but the code is ok to me.
Re:YouTube Video as Background in React by izietto on Sunday March 27, 2022 @06:17AM (#30819137)
I count 213 JS + 41 CSS = 254 lines
Re:YouTube Video as Background in React by 11235813213455 on Sunday March 27, 2022 @08:23AM (#30819700)
Re:YouTube Video as Background in React by naoqj on Sunday March 27, 2022 @06:47AM (#30819256)
You forget the dependencies.
Re:YouTube Video as Background in React by CapsAdmin on Sunday March 27, 2022 @07:12AM (#30819367)
of course.. :-)

I'm not sure what we're talking about here because it's not very obvious where this number comes from. Is it the YouTube API, excluding React?

If you're thinking of using a React library, we have to assume you're already using React.

Mentioning line count is useless unless you're someone intending to explicitly manage that code. But if so, why stop at 40k?

It seems more constructive to talk about the size impact in megabytes or loading time of requiring the YouTube API just to have video playing in the background vs just just hosting your own static video alongside the html. Of course assuming you already use React.

Re:YouTube Video as Background in React by amelius on Sunday March 27, 2022 @06:15AM (#30819131)
It would be nice to have a downvote button on stories, even if it does nothing.
Re:YouTube Video as Background in React by zfxfr on Sunday March 27, 2022 @05:49AM (#30819025)
Do we really need react for this ? Also it looks like there are thousands of LOC for just this
Re:YouTube Video as Background in React by pcthrowaway on Sunday March 27, 2022 @07:10AM (#30819359)
You certainly don't need react to embed a youtube video in a background.. this library provides a react component that does this, which is useful to react users who want this effect.
Re:YouTube Video as Background in React by BigJono on Sunday March 27, 2022 @08:01AM (#30819593)
The amount of code used here to do something so simple is absolutely staggering. This library abstracts over youtube-react, which abstracts over youtube-player, which abstracts over the Youtube API itself, each one proving hundreds or thousands of LoC.

This is a serious dependency sandwich. If you want to put a single Youtube video in the background of a div then you don't need thousands of lines of code for managing player controls and state changes. You could probably take 1/10th of that code in youtube-react (the bit that integrates a react component with a 3rd party lib that wants control over the DOM, common pattern with React) and get the same result.

Re:YouTube Video as Background in React by dismantlethesun on Sunday March 27, 2022 @08:20PM (#30825579)
What you are saying is a worthy fault for a front end library, but it’s kind of funny that no one thinks this way when it’s the backend.

To do a simple k-means clustering on a textual corpus, someone might pull in all of scipy and ntlk which is tens of thousands of lines of code.

I think programmers don’t generally consider dependency size unless it’s on the order of multiple gigabytes.

Re:YouTube Video as Background in React by pcthrowaway on Sunday March 27, 2022 @09:08PM (#30825911)
I suspect a lot more LoC are fetched when you visit youtube anyway, even if it is edge-optimized
Re:YouTube Video as Background in React by wackget on Sunday March 27, 2022 @09:23PM (#30826015)
You just described the entire pantheon of modern development tools.
Re:YouTube Video as Background in React by beastman82 on Sunday March 27, 2022 @07:41AM (#30819485)
How about everyone who isn't impressed just don't upvote it or comment and let the algorithm work
Re:YouTube Video as Background in React by throwaway_1237 on Sunday March 27, 2022 @04:46AM (#30818754)
Would be nice to have a link to an example.
Re:YouTube Video as Background in React by CapsAdmin on Sunday March 27, 2022 @06:50AM (#30819271)
Can you reliably autoplay video and audio in current browsers?
Re:YouTube Video as Background in React by CapsAdmin on Sunday March 27, 2022 @06:54AM (#30819294)
i figured out it should work if it starts out muted