react-use icon indicating copy to clipboard operation
react-use copied to clipboard

Would like to see a way installing any hook as an independent module if reasonable

Open AndrewJHart opened this issue 5 years ago • 2 comments

Is your feature request related to a problem? Please describe. No

Describe the solution you'd like Ideally, being able to install a hook individually. However, I am aware that this has caveats and even lodash is deprecating this functionality in its next major release (v5) because using one module is fine, but the dependencies are pulled into that module w/i node_modules, thus if you use 2 or 3 of these lodash methods as separate packages it can be become more cumbersome. To quote the author:

Although they may seem more lightweight, they will usually increase the size of node_modules and webpack/rollup bundles in a project that transitively depends on multiple per method packages and/or the main lodash package. Whereas many methods in the main lodash package share code, the per method packages internally bundle copies of any code they depend on.

For example, throttle uses debounce internally. In a project using both methods from the main lodash package, throttle will import the same debounce module as any code that imports debounce directly, so only one copy of debounce will wind up in a webpack bundle.

On the other hand, if a project imports throttle from lodash.throttle, the extra copy of the debounce code internally bundled into lodash.throttle will wind up in the webpack bundle, in addition to debounce from the main lodash package or lodash.debounce.

Now I haven't looked at the library to see how its laid out or if one hook depends on another, etc.. if this is not an issue and I could see why it might not be as much of one with hooks then installing single hooks would be awesome.

However, I am also aware that modern tree-shaking bundlers such as webpack can avoid bundling code you don't use or need. So maybe the entire idea is moot. Just wanted to share thoughts.

Describe alternatives you've considered Due to concerns above, perhaps It would be nice if I could install a subset of hooks, say by the way they are organized. This would keep the application size smaller and give me maybe just 1 or 2 hooks that i'd be likely to use in the same app.

AndrewJHart avatar Oct 23 '20 19:10 AndrewJHart

I'd also like to see this 👍🏻 Side note: There's an existing issue open for this #1019

ammmze avatar Jan 29 '21 22:01 ammmze

Yup, 1019 's title should be updated to be more search friendly, and this issue closed.

broofa avatar Dec 04 '23 12:12 broofa