antonioru / beautiful-react-hooks

🔥 A collection of beautiful and (hopefully) useful React hooks to speed-up your components and hooks development 🔥

Home Page:https://antonioru.github.io/beautiful-react-hooks/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

remove index.ts from the codebase to force correct imports

antonioru opened this issue · comments

commented

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:

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):

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 :)

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.

commented

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 :))

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.

commented

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