File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " eslint-plugin-react-server-components " : minor
3+ ---
4+
5+ allow useMemo hook in RSC
Original file line number Diff line number Diff line change @@ -171,6 +171,36 @@ export function Foo() {
171171}` ,
172172 options : [ { allowedServerHooks : [ "useTranslations" ] } ] ,
173173 } ,
174+ {
175+ code : `import React from 'react';
176+ export function Foo({id}) {
177+ const t = React.useState(id);
178+ return <button id={t} />;
179+ }` ,
180+ options : [ { allowedServerHooks : [ "useState" ] } ] ,
181+ } ,
182+ {
183+ code : `import * as React from 'react';
184+ export function Foo({id}) {
185+ const t = React.useState(id);
186+ return <button id={t} />;
187+ }` ,
188+ options : [ { allowedServerHooks : [ "useState" ] } ] ,
189+ } ,
190+ {
191+ code : `import {useMemo} from 'react';
192+ const Button = ({id}) => {
193+ const memoizedId = useMemo(() => id, [id]);
194+ return <div id={memoizedId} />;
195+ }` ,
196+ } ,
197+ {
198+ code : `import React from 'react';
199+ const Button = ({id}) => {
200+ const memoizedId = React.useMemo(() => id, [id]);
201+ return <div id={memoizedId} />;
202+ }` ,
203+ } ,
174204 ] ,
175205 invalid : [
176206 {
Original file line number Diff line number Diff 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- / ^ u s e [ A - Z ] / . test ( name )
85+ / ^ u s e (? ! ( I d | M e m o ) $ ) [ A - Z ] / . test ( name )
8786 ) ;
8887 }
8988
You can’t perform that action at this time.
0 commit comments