noNextAsyncClientComponent
Summary
Section titled “Summary”- Rule available since:
v2.2.0
- Diagnostic Category:
lint/nursery/noNextAsyncClientComponent
- This rule doesn’t have a fix.
- The default severity of this rule is warning.
- This rule belongs to the following domains:
- Sources:
- Same as
@next/no-async-client-component
- Same as
Description
Section titled “Description”Prevent client components from being async functions.
This rule prevents the use of async functions for client components in Next.js applications. Client components marked with “use client” directive should not be async as this can cause hydration mismatches, break component rendering lifecycle, and lead to unexpected behavior with React’s concurrent features.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”"use client";
export default async function MyComponent() { return <div>Hello</div>;}
code-block.jsx:3:16 lint/nursery/noNextAsyncClientComponent ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ The component MyComponent is an async client component, which is not allowed.
1 │ “use client”;
2 │
> 3 │ export default async function MyComponent() {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 │ return <div>Hello</div>;
> 5 │ }
│ ^
6 │
ℹ Client components with “use client” directive should not be async functions as this can cause hydration mismatches and break React’s rendering lifecycle.
ℹ Consider using useEffect for async operations inside the component, or remove the “use client” directive if this should be a server component.
"use client";
export default function MyComponent() { return <div>Hello</div>;}
// No "use client" directive - server component can be asyncexport default async function ServerComponent() { const data = await fetch('/api/data'); return <div>{data}</div>;}
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noNextAsyncClientComponent": "error" } } }}