Too many re-renders with useState and useEffect

There is no need to have a state ‘component’. You should ideally return a component from your switch statement. Here’s the modified codesandbox.

Notice that –

  • I have removed ‘component’ and ‘setComponent’
  • Returned the relevant component in switch statement
  • Cleaned up the map function used inside the return statement.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top