How to fix: ‘Error: Maximum update depth exceeded’

I’m new in React. Have problem with react-router

Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.


          <PrivateRoute path='/' component={Main} /> //without exact
          <Route path='/signin' component={SignIn} />


export const PrivateRoute = ({ component: Component, }) => (
    render={props =>
      localStorage.getItem('authToken') ? (
        <Component {...props} />
      ) : (
          to={{ pathname: '/signin', state: { from: props.location } }}


const Main: FC = () => {
  return (
        { => (


export const routes = [
    path: '/shop',
    key: 'market',
    component: props => (
        component={React.lazy(() => import('./modules/shop/pages/Shop'))}
    path: '/',
    exact: true,
    component: () => <div>main</div>,
    skip: true,


const App: FC<AppProps> = ({ children }) => {
  const classes = useStyles()
  const sidebarToggle = useState(false) // recommended: collapsed, setCollapsed
  return (
    <div className={classes.wrapper}>
      <SidebarContext.Provider value={sidebarToggle}>
        <Sidebar />
        <main className={classes.main}>
          <section className={classes.routeWrapper}>
            <Nav />
            <div className={classes.route}>{children}</div>

So, problem is: without exact route i don’t have this error, but when pass exact props to PrivateRoute, my shop component not works


  1. Basically, exact prop will get rid of nesting ability of Route.

For example, your Main path is '/', so if you pass the exact prop like this:

<PrivateRoute exact path='/' component={Main} />

Then you can’t have a nested route inside Main like /shop, although your shop component is nested inside Main.

  1. As for the infinite loop error, it’s usually because we mutate the component props or states inside the life circle methods (for example: componentDidMount, componentDidUpdate for class-based component, useEffect hook for functional component)

Please make sure there is no where you mutate the props or states directly (without condition) inside the life circle of component. For example, using setState directly inside componentDidUpdate will cause an infinite loop.