Use Next.js advanced <Image/> component with the static export functionality. Optimizes all static images in an additional step after the Next.js static export.
I am using useState, useMemo, and useRouter which are only available on the client. Is there a chance that you change the dynamic import to a string, referencing the image inside your repo? Or use remote images?