title: React Redux: Infinite Loop when dispatch
body: <p>I observed that this problem is common, but I didn't find a solution for my case. </p>
  
  <p>I'm trying to redirect the user to another navigator in react native, using react and redux with redux-thunk. If I display just Home screen it works fine, but when I'm redirecting from SignIn screen to Home, it goes into an infinite loop, I found the problem is in the dispatch function.</p>
  
  <pre><code>import {
    FETCHING_CATEGORIES_REQUEST,
    FETCHING_CATEGORIES_SUCCESS,
    FETCHING_CATEGORIES_FAILURE,
  } from "../types"
  
  import { Categories } from "../../services/firebase"
  
  export const fetchingCategoriesRequest = () =&gt; ({
    type: FETCHING_CATEGORIES_REQUEST,
  })
  
  export const fetchingCategoriesSuccess = data =&gt; ({
    type: FETCHING_CATEGORIES_SUCCESS,
    payload: data,
  })
  
  export const fetchingCategoriesFailure = error =&gt; ({
    type: FETCHING_CATEGORIES_FAILURE,
    payload: error,
  })
  
  export const fetchCategories = () =&gt; {
    return async dispatch =&gt; {
      dispatch(fetchingCategoriesRequest())
      Categories.get()
        .then(data =&gt; dispatch(fetchingCategoriesSuccess(data)))
        .catch(error =&gt; dispatch(fetchingCategoriesFailure(error)))
    }
  }
  </code></pre>
  
  <p>Routing</p>
  
  <pre><code>import { createSwitchNavigator } from "react-navigation"
  
  import PrivateNavigator from "./private"
  import PublicNavigator from "./public"
  
  const Navigator = (signedIn = false) =&gt; {
    return createSwitchNavigator(
      {
        Private: {
          screen: PrivateNavigator,
        },
        Public: {
          screen: PublicNavigator,
        },
      },
      {
        initialRouteName: signedIn ? "Private" : "Public",
      },
    )
  }
  
  export default Navigator
  </code></pre>
  
  <p>Redirecting</p>
  
  <pre><code>import React from "react"
  import { Spinner } from "native-base"
  import { connect } from "react-redux"
  import Navigator from "../navigation"
  
  class AppContainer extends React.Component&lt;any, any&gt; {
    render() {
      const { isLogged, loading } = this.props.auth
  
      const Layout = Navigator(isLogged)
      return loading ? &lt;Spinner /&gt; : &lt;Layout /&gt;
    }
  }
  
  const mapStateToProps = state =&gt; {
    return {
      ...state,
    }
  }
  
  export default connect(
    mapStateToProps,
    {},
  )(AppContainer)
  </code></pre>