title: convert reducer from react redux to hooks
body: <p>I am making a login/ registration app. I am trying to convert a reducer for a class based component to use with hooks. This is the reducer :</p>
  <pre><code>import { SET_CURRENT_USER, USER_LOADING } from &quot;../actions/types&quot;;
  
  const isEmpty = require(&quot;is-empty&quot;);
  
  const initialState = {
    isAuthenticated: false,
    user: {},
    loading: false
  };
  
  export default function(state = initialState, action) {
    switch (action.type) {
      case SET_CURRENT_USER:
        return {
          ...state,
          isAuthenticated: !isEmpty(action.payload),
          user: action.payload
        };
      case USER_LOADING:
        return {
          ...state,
          loading: true
        };
      default:
        return state;
    }
  }
  
  </code></pre>
  <p>How can I convert this to reducer for use in hooks functional component?</p>
  <p>This is my login component:</p>
  <pre><code>function Login (props) {
   
        const [email, setEmail] = useState(&quot;&quot;);
        const [password, setPassword] = useState(&quot;&quot;);
        const [errors, setErrors] = useState([]);
   useEffect(() =&gt; {
      if (props.auth.isAuthenticated) {
        props.history.push(&quot;/dashboard&quot;);
      }
    });
  useEffect(() =&gt; {
      if (props.auth.isAuthenticated) {
        props.history.push(&quot;/dashboard&quot;);
      }
    }, [props.auth]);
  const onSubmit = e =&gt; {
      e.preventDefault();
  
      const userData = {
        email: email,
        password: password
      };
  
      props.loginUser(userData);
    };
   form data....
  
  </code></pre>