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 Retrieve the Selected Value from a Select Field in ReactJS and NextJS
- Next js unhandled runtime error Invalid src prop
- PersistGate' cannot be used as a JSX component. Its instance type 'PersistGate' is not a valid JSX element.
- How to change the background of a selectfields dropdown using css or tailwind
- Deployment RollupError: Could not resolve "./Features/Home/Home.jsx" from "src/App.jsx"
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.