Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-spies-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-simplikit': patch
---

fix(usePrevious): opt out `usePrevious` hook from React Compiler
4 changes: 4 additions & 0 deletions packages/core/src/hooks/usePrevious/usePrevious.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const strictEquals = <T>(prev: T, next: T) => prev === next;
* const previousCount = usePrevious(count);
*/
export function usePrevious<T>(state: T, compare: (prev: T, next: T) => boolean = strictEquals): T {
// Without `'use no memo'`, React Compiler throws when `panicThreshold` is not `'none'`
// because this hook intentionally reads and updates refs during render.
'use no memo';

const prevRef = useRef<T>(state);
const currentRef = useRef<T>(state);
const isFirstRender = useRef<boolean>(true);
Expand Down