React Compiler
StableAutomatic optimization that eliminates the need for manual memoization with useMemo, useCallback, and React.memo.
with clerk · Works seamlessly with all Clerk hooks - the compiler automatically optimizes re-renders when auth state changes.
- Eliminates need for manual memoization
- Reduces boilerplate code
- Automatic performance optimization
- Better developer experience
view code
// Before React 19 (manual memoization)
const MemoizedUserProfile = React.memo(({ user }) => {
return <div>{user.firstName}</div>;
});
const memoizedValue = useMemo(() =>
computeExpensiveValue(user),
[user]
);
const memoizedCallback = useCallback(() => {
handleUserAction(user);
}, [user]);
// After React 19 (automatic with React Compiler)
function UserProfile({ user }) {
// Compiler automatically memoizes
const value = computeExpensiveValue(user);
const handleClick = () => {
handleUserAction(user);
};
return <div onClick={handleClick}>{user.firstName}</div>;
}"use client";
import { useUser } from "@clerk/nextjs";
// React Compiler automatically optimizes this
export default function OptimizedUserProfile() {
const { user, isLoaded } = useUser();
// No need for useMemo - compiler handles it
const displayName = user?.firstName || "Guest";
const emailCount = user?.emailAddresses.length || 0;
// No need for useCallback - compiler handles it
const handleProfileUpdate = () => {
console.log("Updating profile for", user?.id);
};
if (!isLoaded) return <div>Loading...</div>;
return (
<div>
<h1>{displayName}</h1>
<p>{emailCount} email(s)</p>
<button onClick={handleProfileUpdate}>Update Profile</button>
</div>
);
}