vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
6.37k stars 1.3k forks source link

Why does this code not throw an error? #367

Open nwaokoron opened 1 month ago

nwaokoron commented 1 month ago

https://github.com/vercel/nextjs-subscription-payments/blob/25a19504c85a2353f23e907521d0cdb1979c66d6/components/ui/Navbar/Navlinks.tsx#L4

Pretty new to Next.js. I thought importing a server component in a client component would cause an error but this code seems to allow it. How so?

k-thornton commented 1 month ago

Since you're new to Next.js this might be your first encounter with Server Actions https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#event-handlers

They're great, it makes it so you can write vanilla functions that run on your server and call them from your client side, instead of having to make a bunch of API endpoints and HTTP calls. That all happens behind the scenes. Once you're comfortable with server actions it's really hard to go back to API routes!