Skip to content

Commit e8241dd

Browse files
committed
feat: allow useMemo hook in server components
1 parent d3c3cf6 commit e8241dd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/rules/use-client.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ export function Foo() {
171171
}`,
172172
options: [{ allowedServerHooks: ["useTranslations"] }],
173173
},
174+
{
175+
code: `import {useMemo} from 'react';
176+
const Button = ({id}) => {
177+
const memoizedId = useMemo(() => id, [id]);
178+
return <div id={memoizedId} />;
179+
}`,
180+
},
174181
],
175182
invalid: [
176183
{

src/rules/use-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ const create = Components.detect(
8181
function isClientOnlyHook(name: string) {
8282
return (
8383
// `useId` is the only hook that's allowed in server components
84-
name !== "useId" &&
8584
!(options.allowedServerHooks || []).includes(name) &&
86-
/^use[A-Z]/.test(name)
85+
/^use(?!(Id|Memo)$)[A-Z]/.test(name)
8786
);
8887
}
8988

0 commit comments

Comments
 (0)