Skip to content

Commit

Permalink
feat: allow useMemo hook in server components
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwlad90 committed Jul 24, 2024
1 parent d3c3cf6 commit e8241dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/rules/use-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ export function Foo() {
}`,
options: [{ allowedServerHooks: ["useTranslations"] }],
},
{
code: `import {useMemo} from 'react';
const Button = ({id}) => {
const memoizedId = useMemo(() => id, [id]);
return <div id={memoizedId} />;
}`,
},
],
invalid: [
{
Expand Down
3 changes: 1 addition & 2 deletions src/rules/use-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ const create = Components.detect(
function isClientOnlyHook(name: string) {
return (
// `useId` is the only hook that's allowed in server components
name !== "useId" &&
!(options.allowedServerHooks || []).includes(name) &&
/^use[A-Z]/.test(name)
/^use(?!(Id|Memo)$)[A-Z]/.test(name)
);
}

Expand Down

0 comments on commit e8241dd

Please sign in to comment.