Skip to content

Commit fa2b9f7

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

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/loud-terms-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-react-server-components": minor
3+
---
4+
5+
allow useMemo hook in RSC

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)