-
-
Notifications
You must be signed in to change notification settings - Fork 450
Description
Describe the bug
When I only use a certain part of usehooks-ts, just like: useInterval useIsomorphicLayoutEffect.
When I want to build the lib dist. It will always include the part of requireLodash_debounce source code.
When my project have 5 sub-package, their dist will hold 5 requireLodash_debounce source code. It's terrible.
It's not requirement for useInterval and useIsomorphicLayoutEffect.
So always, I will need to keep the file like this usehooks-ts.ts in every project to exclude requireLodash_debounce:
import { useEffect, useLayoutEffect, useRef } from 'react';
export const useIsomorphicLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
export function useInterval(callback: () => void, delay: number | null) {
const savedCallback = useRef(callback);
// Remember the latest callback if it changes.
useIsomorphicLayoutEffect(() => {
savedCallback.current = callback;
}, [callback]);
// Set up the interval.
useEffect(() => {
// Don't schedule if no delay is specified.
// Note: 0 is a valid value for delay.
if (delay === null) {
return;
}
const id = setInterval(() => {
savedCallback.current();
}, delay);
return () => {
clearInterval(id);
};
}, [delay]);
}It's very hard to maintain to keep align to usehooks-ts newest version.
Would you keep the old dist mode (like 2.6.0), or add a exports point to resolve this problem?
To Reproduce
A sub-project dependencies to usehooks-ts, and use any hook like useIsomorphicLayoutEffect.
Use rollup to build the sub-project dist.
The dist source will always include the requireLodash_debounce.
Expected behavior
When I not use useDebounceCallback (import by my source), the requireLodash_debounce should not include to the dist source.
Additional context
No response