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

 

message profile
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(

  )
}

 

Add Message

Click on the button below to add a new message to this thread

Tags

#Javascript #next js

Thread detail

Satus: Open
Messages: 1Started: 2023-02-20
loading..

DEVMAESTERS

Newsletter

Services

Frontend Development |Backend Development |Full Website Development |Bootstrap Website upgrades | Website Debbugging | Website Hosting & deployment

Contact

Interested in hiring me or collaborating with me on a project, click on any of the links below to get my social media handle

Or contact me via Tel: (+234)-806-225-7480 | Email: abubakarzakari1703@gmail.com

Copywright@devmaesters.com
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.