Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow certain hooks to be used in before or after certain other hooks, but not at any place #11

Open
simonseyock opened this issue Sep 26, 2023 · 0 comments

Comments

@simonseyock
Copy link

For my program I have made the distinction between hooks that provide state (like useState), that consume state (like useEffect) and ones that do both (useCallback or useMemo).

For the first and second group the order can be static, but for the third one I could need to call useCallback before useMemo or vice versa. Because they can use each other as dependencies:

const memoized = useMemo(() => (/* ... */), []);
const callback = useCallback(() => (/* ... */), [memoized]);
// vs
const callback = useCallback(() => (/* ... */), []);
const memoized = useMemo(() => (/* ... */), [callback]);

For these two hooks it may seem a little constructed, but for other (custom) hooks this will be important.

I would wish I could specify an array inside the groups config so I can order these specific functions as I like, but not at any place in the file. The config could look like this:

'hooks/sort': [2, {
  groups: [
    'useState',
    ['useMemo', 'useCallback'],
    'useEffect'
  ]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant