antonioru / beautiful-react-hooks

🔥 A collection of beautiful and (hopefully) useful React hooks to speed-up your components and hooks development 🔥
https://antonioru.github.io/beautiful-react-hooks/
MIT License
8.17k stars 577 forks source link

remove index.ts from the codebase to force correct imports #378

Closed antonioru closed 2 years ago

antonioru commented 2 years ago

Discussed in https://github.com/antonioru/beautiful-react-hooks/discussions/377

Originally posted by **antonioru** June 28, 2022 The correct way to import hooks from this library is: ```ts import useSomething from 'beautfiul-react-hooks/useSomething'; ``` but I've noticed quite often people just go with the ES6 named imports like (probably because it's suggested by the IDE): ```ts import { useSomething } from 'beautiful-react-hooks'; ``` this will import the whole library, which might result in increasing the bundle size. To solve this I would like to remove the `index.ts` file from the library and "force" the developers to use the default imports. This will obviously be a breaking change so I'd like to have some opinions here :)
playerony commented 2 years ago

The package does not support tree shaking, that we should make such a drastic change? At the end of the day, bundled javascript by any and maintained bundler should three shake dead code.

antonioru commented 2 years ago

The package does not support tree shaking, that we should make such a drastic change? At the end of the day, bundled javascript by any and maintained bundler should three shake dead code.

I understand your point and yes, I think you're correct assuming that 99% of the times one is using this library they're definitely using React which probably means they're using webpack or rollup or vite or anything of that sort...

on the other hand, three-sharking is not an automatic feature, it has to be configured and therefore can be mis-configured by the user.

I wonder if it's our duty to "force" the user to write "good code" by imposing default exports... I don't have an answer to be honest :))

playerony commented 2 years ago

So I think if it's a 99% of the user's bundlers coverage + to be honest it's a breaking change and I'm not sure if necessary and worth change.

antonioru commented 2 years ago

So I think if it's a 99% of the user's bundlers coverage + to be honest it's a breaking change and I'm not sure if necessary and worth change.

fair enough... I'll do some research so I can possibly propose the right solution. I'm closing this issue for now then