React hooks have a serious duplication problem

https://nikgraf.github.io/react-hooks -> filter by "online" or just google for any network status hooks.

They nearly all have this exact structure, a copy-paste job from a tut...

This is an incomplete online check (having network !== being online) and I've just wasted 20 minutes of my time browsing the code of different hooks and hook-libraries looking for one that does a better check than the offline/online events. It's astounding to me that I can easily find 10 that are just the same code with different variable names.

It's also striking that many published hooks have barely any or just no documentation, especially in the libraries that have a bunch. How are you supposed to evaluate that this actually solves your specific problem?

Why is this happening? This seems very bad for the ecosystem.

Posted Oct 8, 2019, 7:45 AM UTC

815
illuminist_ova•

Open ecosystem in a nut shell. Just stick to any famous library or make a custom hook that suite your need by yourself.

21
averageFlux•

This is not problem with React hooks, as the title suggests, but a product of any open source project out in the wild.

What can you do? Keep yourself in the loop and check what the code you are importing does.

18
GriffinsauceOP•

So that's kinda my point: I feel like it's worse with hooks. Maybe because they can be very small and are new but I can't remember the last time I compared regular JS modules with this outcome.

And, yes I do that, but because of the massive amount of copy-paste stuff it feels very wasteful.

0
skyboyer007•

alternative is having just few vendors allowed to add new features. would it be good to ecosystem?

6
evolutionxbox•

Lazy code to be the first hooks library out there?

5
GriffinsauceOP•

Perhaps, a bunch are definitely trying to be the underscore/lodash of hooks

1
nickbreaton•

Yeah I wish this wasn’t the case. I think it’s pretty unnecessary. I’d prefer to install specific hooks when needed, and for my use case so far that is very few.

3
joesb•

Nothing forces you to use those libs.

5
[deleted]•

Then you've missed the point of this post.

-3
GriffinsauceOP•

Exactly.

-2
timhwang21•

Same thing happened with everyone and their dog having a flux implementation, then a "simple redux" implementation, etc. The majority of which are learning projects and/or resume driven development.

Eventually the community will collectively realize which ones are high quality. But until then it's on you to audit and figure out which ones are good.

3
GriffinsauceOP•

I guess so, I wish the react people like Dan would push more for reuse and contribution. A tut could describe the process and then point to a module to contribute improvements to for instance.

1
acemarke•

"Reuse and contribution"... to what?

One of the React team's specifically expressed desires for hooks is that in many cases they can be copy-pasted. Sure, you can turn them into NPM packages (for just one hook or many), but in most cases there's no need to. So yeah, the React team explicitly hopes people copy-paste hooks as needed.

0
stolinski•

I think the answer with any of this stuff is to always look at the source of anything you’re going to install, especially hooks library’s because they’re not usually that large. If you don’t like what you see in the source you can always copy and paste use it as a starting point and modified to your liking or just write it from scratch. But I don’t really think this is a problem with hooks specifically. 

2
Sonicrida•

Look at the source code, test the hooks out, and look at only ones with proper documentation. You can also sort by what is being used frequently or has a lot of stars.

1