roginfarrer / eslint-plugin-react-server-components

ESLint rule for enforcing "use client" in React client components
MIT License
30 stars 4 forks source link

Create an exception for the eslint rule regarding server actions #12

Open shyuuuuni opened 4 months ago

shyuuuuni commented 4 months ago

Using server action, we can pass functions as props in server components.

The example below is taken from the Next.js server action post.

export default function Page() {
  async function createInvoice(formData: FormData) {
    'use server'

    const rawFormData = {
      customerId: formData.get('customerId'),
      amount: formData.get('amount'),
      status: formData.get('status'),
    }

    // mutate data
    // revalidate cache
  }

  return <form action={createInvoice}>...</form>
}

The lint rule is triggered at the <form action={createInvoice}>...</form> part of the example above.


package version

roginfarrer commented 4 months ago

PRs welcome! Otherwise I'll try to get to this sometime soon.