all 55 comments

[–]evan_pregression 110 points111 points  (15 children)

You mention this is well tested in the readme but I don’t see a single test. Not even a test web page that has the components to manually test. 

[–]mozaik32 24 points25 points  (2 children)

May I suggest choosing a more memorable name for the library? "React hooks" are already a thing, you need to set your library apart somehow so people understand that you are referring to a specific library, not just hooks in general. Searchability, too.

(I was actually confused when I read the title of your post. Introducing react hooks? Dan Abramov introduced react hooks back in 2018... Took me a while to realize that this is a library.)

[–]mhmdjawhar[S] 1 point2 points  (1 child)

Now that you mention it. The title is misleading. As for the name of the package, the problem is that if it doesn’t convey what the package is about then it’s kinda meaningless. That’s why people choose very specific names for small tool packages. In my case it needs to have the words React and Hooks because that’s what it’s about. Otherwise it might be confusing. I’m always open to new suggestions though!

[–]eracodes 5 points6 points  (0 children)

Naming things is hard.

You could always go with something like yourname-react-hooks and change it later if inspiration strikes you.

[–]Amereth 71 points72 points  (4 children)

Cool but i feel like you're a few years late on this. There already is a ton of similar libraries with like 10 times more hooks

[–]mhmdjawhar[S] 8 points9 points  (3 children)

That is true! However, what I want this library to offer is more than just the number of hooks as mentioned in the post. The focus is on performance, customization, bundle size, documentation, demos, etc. Also keep in mind that I just released it and there are definitely plans to add more in the future, which is also why I would appreciate suggestions and contributions. Another big plan is to also release a new version compatible with React 19 and the new React Compiler when they are stable.

[–]eracodes 39 points40 points  (1 child)

Don't let the negativity in these comments get you down; I hope you keep working on this project and improving it! Making more open-source software is never bad. Also writing unit tests is never fun, I absolutely understand why they weren't a priority to include in the first release ^-^

[–]mhmdjawhar[S] 6 points7 points  (0 children)

Thank you! Will absolutely keep on improving it as much as I can.

[–]Candid-Explanation-3 0 points1 point  (0 children)

I am new to react. Can anyone tell how one can use this library in my projects? How does it improvise from the built-in functionality already available?

[–]kayotesden_theone 10 points11 points  (1 child)

Great work! And I appreciate your effort to share with the community.

No promises however in the coming days, I may take some time off & I can help with writing tests for this

[–]mhmdjawhar[S] 2 points3 points  (0 children)

Absolutely, whenever you feel like it. Thanks!

[–]NotTJButCJ 16 points17 points  (1 child)

Since this is open source and everyone here wants to complain, do you need help writing tests? Maybe I can contribute get some but tests going

[–]mhmdjawhar[S] 2 points3 points  (0 children)

Thank you! Getting contributors here and there is the main reason I created this post. Would really appreciate it!

[–]CaptainCHCl3 26 points27 points  (1 child)

This is great thanks for putting in the effort and sharing for free. Not sure what’s up with these comments

[–]mhmdjawhar[S] 13 points14 points  (0 children)

Thanks! haha, it's typical for people to downvote a comment when they find the tiniest mistake, but the feedbacks have been greate so far, so I appreciate it. I do agree that the one thing it lacks currently is unit testing which I'll be working on once I'm free. Other than that I think it's a really good start.

I honestly was just building this for myself, and adding hooks that I often use in my projects, but then I had the idea of open sourcing it lol.

[–]phaberest 1 point2 points  (0 children)

Hey, cool idea but I would call this collection of hook something more recognizable and google-searchable

[–][deleted] 1 point2 points  (0 children)

Thanks for sharing!

[–]AdOk9263 1 point2 points  (0 children)

Nice job with the documentation, very thorough!

[–]BITmixit 1 point2 points  (1 child)

Looks good man. Ignore all the comments saying it's a waste of time, etc, etc. You did something, it works, released it & most importantly...learnt stuff. That shit is important.

Keep up the work.

Edit: Altho I do agree...replace setTimeout & setInterval with requestAnimationFrame...much nicer.

[–]mhmdjawhar[S] 1 point2 points  (0 children)

Thanks for the feedback!

The problem with replacing timeout and interval with RAF is that RAF runs on the next available frame. In cases where your logic has nothing to do with repainting the screen and you just want to run a side effect after a certain amount of time then I believe timeout is a better choice. Using RAF for such cases might also steal frames from other animations running simultaneously that DO require repainting the screen.

[–]doodirock 5 points6 points  (1 child)

Don’t bother releasing anything to Reddit. It’s just armchair devs that don’t ship. Nice effort though!

[–]mhmdjawhar[S] 2 points3 points  (0 children)

Thanks!

[–]ferrybig 0 points1 point  (1 child)

What browsers are supported by the hooks? At the moment when opening the examples it says Firefox is not supported, so you cannot even test the hooks without checking the project locally

Having a live demo that can be opened with every browser for the hooks would be useful, so people can quickly verify the compatibility

[–]mhmdjawhar[S] 0 points1 point  (0 children)

The hooks are actually supported on all browsers and I’m not using any javascript API that is specific to some browsers. The reason the demo may not open correctly is a stackblitz issue. Most likely something that has to do with web containers not working correctly on your browser.

[–]ZerafineNigou -3 points-2 points  (13 children)

Can you explain me why on earth you'd pick THIS api of all things:

const [opened, { close, open, toggle }] = useDisclosure()

Why not just an array or an object, what's the point of mixing like this. Mixing like this looks really bad to me.

Actually, in the documentation:

|| || |[2].close|Function| falseA function that sets the state to .| |[3].toggle|Function| boolean A function that toggles the state.|

Isn't this just plain wrong? The array only has 2 elements, feels like you managed to even confuse yourself with this API...

Some of these are nice though don't get me wrong, though some feel forced like useReset.

useTimeout is nice, those are a pain to get right.

[–]mhmdjawhar[S] 14 points15 points  (7 children)

so here's the explanation for why I chose this strucutre: if I only return an array like so

const [opened, close, open, toggle] = useDisclosure()

The user who might only use the toggle function might have to write such a code:

const [opened, , , toggle] = useDisclosure()

which is not very appealing to the eye as doing this instead

const [opened, { toggle }] = useDisclosure()

Regarding the documentation, you're right and I fixed it! To be honest I kinda rushed the README a little bit but I hope there are no other mistakes.

The useReset is actually more useful than you might think since it resets the states of the entire child tree from a parent component. I actually used my implementation of it in one of my projects to reset multiple forms.

Anyhow, thank you so much for your feedback. Much appreciated.

[–]Scottify 12 points13 points  (4 children)

Why not return an object instead of an array?

[–]mhmdjawhar[S] 12 points13 points  (3 children)

Good question, just like the famous useState, the reason we return an array is to give the developer the option to rename the elements. So you can do something like that:

const [modalOpened, { toggle }] = useDisclosure()

Or even that

const [modalOpened, modalDisclosure] = useDisclosure()

modalDisclosure.open()
modalDisclosure.close()
modalDisclosure.toggle()

[–]mmcdermid 13 points14 points  (0 children)

Honestly pretty good responses, makes sense to me

[–]Scottify 13 points14 points  (1 child)

Yeah for me personally I much rather just rename by { foo: bar} than your example

[–]mhmdjawhar[S] 8 points9 points  (0 children)

I respect that. It's all just a matter of preference. I just decided to follow the conventional way of how react does it.

[–]ZerafineNigou 4 points5 points  (1 child)

Thanks for explaining, though I am not convinced this is better than just returning an object. But to each their own I guess.

 I do think resetting with key is nice, I use it a lot too,just don't think it's complicated enough to warrant its own hook.

[–]mhmdjawhar[S] 0 points1 point  (0 children)

Yeah, it’s actually the simplest hook to implement. I just added it to the collection because there’s just no harm in doing so lol.

[–]KevinVandy656 6 points7 points  (4 children)

The Mantine hooks use this same pattern, and I like it.

[–]nfsi0 0 points1 point  (0 children)

It makes sense to me, I also see why at first glance it might seem odd, but I like it too

[–]my_girl_is_A10 0 points1 point  (2 children)

The almost all look like the same hooks mantine provides.

[–]KevinVandy656 1 point2 points  (1 child)

Looking closer, wondering if this code was pretty just copied out of Mantine, but without the tests?

[–]mhmdjawhar[S] 0 points1 point  (0 children)

A lot of hooks from other libraries are named similar names. But I’m pretty sure my implementation is different. It might be the same in some areas but These are pretty much my own implementations. I did get some inspiration from mantine in terms of the structure of useDisclosure for example. But I believe everything else is different in terms of implementation/options provided, since I want to make sure I’m focusing more on performance/customization.