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 fa2b9f7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-terms-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-react-server-components": minor
---

allow useMemo hook in RSC
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 fa2b9f7

Please sign in to comment.