Error: React Hook "useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render. react-hooks/rules-of-hooks
Executing npm run build for my Next.js project outputs the error below
Error: React Hook "useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render. react-hooks/rules-of-hooks
Admin
2023-02-20
To fix this error move all your hook calls (useEffect, useState e.t.c to the top of your function component. An example is shown below
function Information() {
const router = useRouter();
const { isDark } = useTheme();
const [user, setUser] = useState(undefined);
const [value, setValue] = useState({ name: "Nigeria", code: "ng" });
const [value2, setValue2] = useState(states[0]);
//rest of your code
return(
)
}
Similar Content
- How to read system images in an electron-react app
- How to use external stylesheets in next.js
- error: API resolved without sending a response for /XXXX/XXXX, this may result in stalled requests.
- Setting up dynamic sitemap for next js using Javascript
- PersistGate' cannot be used as a JSX component. Its instance type 'PersistGate' is not a valid JSX element.
Privacy Policy
By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.