react
Hook called outside component or custom hook
React Hook .+ cannot be called at the top level
Fixes
- 1.Move the hook call inside a function component or a custom hook (function starting with 'use')
- 2.Ensure the file exports a component or custom hook, not a plain function
- 3.Check that the function name starts with an uppercase letter (component) or 'use' (custom hook)
hooksrules-of-hooks
Related Errors
react3 fixes
React hydration mismatch
Hydration failed because.*server rendered HTML.*didn't match
- •Ensure server and client render same content
- •Use suppressHydrationWarning for dynamic content
react3 fixes
Text content hydration mismatch
Text content does not match server-rendered HTML
- •Don't use Date.now() or Math.random() in render
- •Use useEffect for client-only values
react3 fixes
use client directive error in Server Component
(useClient|use client).*server component
- •Add 'use client' at top of file
- •Move useState/useEffect to client component