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
- Error: Invalid `prisma.model.findMany()` invocation. Query engine library for current platform "debian-openssl-1.1.x" could not be found.
- How to make images responsive on web pages
- Adding images to radio buttons using jsx (react & next js)
- How to call more than one function within jsx in next.js and react
- Error: Invalid src prop (https://lh3.googleusercontent.com) on next/image
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.