28 comments

[ 4.7 ms ] story [ 68.5 ms ] thread
It has been a fun journey implementing hooks in React. Let me know your thoughts on the code :)
“Journey” is a bit of a stretch here, no? :)

This is a few lines of pretty trivial code

Maybe he meant more hooks, in general. For me that is true, hooks really are a very inspirational pattern
(comment deleted)
Can you please review the Show HN guidelines? I appreciate that you're not exactly flaming the OP here, but still, the idea is to respond more charitably to people's work. If you know more than others, find a constructive way to express that, such as by teaching them—and by extension, the rest of us—something related to what they've done so far.

https://news.ycombinator.com/showhn.html

https://news.ycombinator.com/newsguidelines.html

This is a great point, and on a second reading my comment did come off as a little insensitive -- will leave it up to give others context and make this a teachable moment for all of us to improve the level of discourse :)
Hey congrats! People will complain about the package being to small or trivial, but just keep on creating. We all start somewhere, and hooks are a fun thing to experiment with.

It's true that most folks probably would do their own implementation of this and the GPL license would be a non-starter for most projects, but if it suits your needs and you've learned something in the process, more power to you. :)

It is a difficult to recommend a small package that is GPLv3, since your entire app would have to be licensed appropriately (since it runs in the same process).

For projects like Blender, where development is a self-reinforcing ecosystem I appreciate what the GPL does, here not so much.

i suspect the choice of GPLv3 was not well informed, given the nature of the code in question.
Mirroring other comments, this seems a bit trivial to be its own package and looking at the source, it seems to not cover cases where the local storage value can't be parsed.

https://usehooks.com/useLocalStorage/ has a safer implementation and is free to copy (Unlicense).

Also not even test cases for such simple code.
I have noticed that, in the wild, referencing window.localStorage at all will raise a security exception in some browsers. If this happens inside of a React hook, it will unmount everything up to the nearest componentDidCatch(). In practice, everything involving localStorage needs to make liberal use of try, catch blocks.
Seconded. localStorage can bite in bad ways, and the unmounting concerns are valid.
(comment deleted)