The End of Manual useMemo and useCallback
The React Compiler (formerly React Forget) analyzes JavaScript semantics at build time and automatically memoizes values and component trees, delivering fine-grained reactivity without human annotation errors.
Using useActionState and useOptimistic
'use client';
import { useActionState, useOptimistic } from 'react';
import { updateProfile } from './actions';
export function ProfileForm({ user }) {
const [state, formAction, isPending] = useActionState(updateProfile, null);
const [optimisticName, setOptimisticName] = useOptimistic(user.name, (curr, next) => next);
return (
<form action={async (formData) => {
setOptimisticName(formData.get('name'));
await formAction(formData);
}}>
<input name="name" defaultValue={optimisticName} />
<button disabled={isPending}>Save Changes</button>
</form>
);
}