Live data from Hacker News

UseHooks – A Collection of Server Component Safe React Hooks

usehooks.com

31–40 of 62 posts

Re: UseHooks – A Collection of Server Component Safe React Hooks

#31

How do these compare with the current heavyweight library? https://github.com/streamich/react-use

From what I've been able to tell, that lib is unmaintained and one of the original authors left and created this – https://github.com/react-hookz/web.

A lot of older hook libs "break the rules" of React by doing some weird stuff like silencing useEffects deps array, reading refs in render, etc. We tried to avoid that so useHooks will be future proof.

Re: UseHooks – A Collection of Server Component Safe React Hooks

#32

Earlier quoted context omitted.

Not a dumb question. I think calling any hooks server component safe is going to mislead and add confusion to a lot of developers for this very new tech. Hooks are not allowed in server components. This library is SSR safe which has been a concern since before server components were ever a thing.

Yeah it's [poor phrasing]( https://twitter.com/tylermcginnis/status/1663648010558132224 ) on our part. How it's being interpreted vs how I thought it would be interpreted are different. We'll update it.

I don't blame you for this. The React team recently talking about "React Server Components" as though most React users are running it on NodeJS backends and introducing magic "use client" strings is putting everyone in a confused position and I don't think there's a good phrasing for you.

Re: UseHooks – A Collection of Server Component Safe React Hooks

#33

How telling is it that a basic core function like useFetch has a warning that it “depends on React’s experimental useEffectEvent”? Almost a decade later and simple data fetching is still an unsolved “problem” in React land.

react is a rendering engine, not a framework; there is no opinionated way to fetch data. react-query is a delightful library that has made data fetching/cacheing a breeze for me - https://tanstack.com/query/v3/docs/react/overview

This may very well change. I won't be surprised to see react have to become more opinionated about days fetching now that they are dancing between client and server with some form of an rpc.

For performance and security I could see them pushing for all data loading to be done on the server, complete with helpers and server-only hooks for fetching and streaming data from the server.

Re: UseHooks – A Collection of Server Component Safe React Hooks

#34

How telling is it that a basic core function like useFetch has a warning that it “depends on React’s experimental useEffectEvent”? Almost a decade later and simple data fetching is still an unsolved “problem” in React land.

I can’t seem to even find useFetch in the source….

Re: UseHooks – A Collection of Server Component Safe React Hooks

#35

How telling is it that a basic core function like useFetch has a warning that it “depends on React’s experimental useEffectEvent”? Almost a decade later and simple data fetching is still an unsolved “problem” in React land.

I guess you are thinking that because it has a simple name on the website, "useFetch", that it's some sort of canonical http client for React, but it's not.

The only thing it telegraphs is that the ui.dev people built an http client hook (with opinionated features like caching) that uses cutting edge features to do things that people are already doing in React without experimental features.

Re: UseHooks – A Collection of Server Component Safe React Hooks

#36
post #4

I think it's great to have a repo of all the hooks, but I wonder if implementing each from scratch is the right approach. For example, there is an exceptional useDebounce package [0] that handles many more cases than the simplified one on UseHooks, and I think it could be even more useful to highlight exceptional work that has already been done and maintained in the community rather than in-housing everything. I also…

Some companies have strict policies on adding new dependencies to an existing project (no matter how small), so packages like this provides tens of hooks with the effort of a single arguing session about one dependency. It's very useful for those cases.

Re: UseHooks – A Collection of Server Component Safe React Hooks

#37

I don’t understand why this should be distributed as a package of many hooks. Unless if a hook is unusually complicated, I much rather copy-paste it into my code. You should really share the implementations of each of them on the website. I don’t want to pull in 100 hooks just because I don’t want to write 1 from scratch.

Copy/pasting is fine. You do you. https://github.com/uidotdev/usehooks/blob/main/index.js

Actually, the repository has an MIT license. You can't copy/paste them without also including the license file.

Re: UseHooks – A Collection of Server Component Safe React Hooks

#38
post #3

Earlier quoted context omitted.

Are all the hooks on the site made by ui.dev? It'd be great if each hook linked to the Github code for that hook, as the first thing I thought of was (a) what is the hook doing, and (b) is it easier to adapt my existing hook and reduce the number of dependencies I have to track?

Good feedback. Yes they're all up on Github – https://github.com/uidotdev/usehooks

I haven't tried the package yet, but at first glance it is missing the .d.ts file. Is this package type safe?

Re: UseHooks – A Collection of Server Component Safe React Hooks

#40

Nice, thank you. It was only the other day I was copy and pasting from the old site. Looking forward to installing the lib and deleting some code.

That old site was rough . Hopefully this one is a much better experience for you.
Post reply on HN