title: useSelector hook first returns undefined state and after an action call returns the state correctly
body: <p>I'm new with React hooks and I try to integrate my project with redux, the thing is that in a function component that I use for login , when I try to get my initialState properties with useSelector the state is undefined.</p>
  
  <pre><code>import React, {useState} from 'react';
  import loginStyles from './login.module.css';
  import {useDispatch , useSelector, shallowEqual} from 'react-redux';
  import {login} from '../../store/actions/actions';
  
  export default (props) =&gt;  {
  
      const initialState = {
          "email":'',
          "password":''
      }
      const dispatch = useDispatch();
  
      const [loginForm, setValue] = useState(initialState);
  
  
      const changeValue = (event) =&gt; {
          const name = event.target.name;
          const value = event.target.value;
          setValue(prevState =&gt; {
              return {
                  ...prevState,
                  [name]: value
              }
          });
  
      }
  
  
  
      useSelector((state) =&gt; {
         console.log(state)
      });
  
  
      return (
          &lt;article className={loginStyles.main}&gt;
              &lt;aside className={loginStyles.left}&gt;
  
              &lt;/aside&gt;
              &lt;aside className={loginStyles.right}&gt;
                  &lt;div&gt;
                      &lt;input name="email" onChange={(event) =&gt; changeValue(event) } type = "text" value = {loginForm['email']} /&gt;
                      &lt;input name="password" onChange={(event) =&gt; changeValue(event) } type = "text" value = {loginForm['password']} /&gt;
                      &lt;button onClick={() =&gt; dispatch(login("jared", true))} &gt;clicl&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/aside&gt;
          &lt;/article&gt;
      );
  
  }
  
  </code></pre>
  
  <p>After I clicked the button it prints out the correct , state but at first render it prints out undefined. So what should I modify?</p>
  
  <p>Here's the rest of my code. Thank you.</p>
  
  <p>App.js</p>
  
  <pre><code>
  import React from 'react';
  import {Provider} from 'react-redux';
  import { createStore } from 'redux';
  import reducer from './store/reducer';
  import Layout from './layouts/main';
  import './app.css';
  function App() {
  
  const store = createStore(reducer);
  
    return (
      &lt;Provider store={store}&gt;
        &lt;Layout /&gt;
      &lt;/Provider&gt;
    );
  }
  
  export default App;
  import React from 'react';
  import {Provider} from 'react-redux';
  import { createStore } from 'redux';
  import reducer from './store/reducer';
  import Layout from './layouts/main';
  import './app.css';
  function App() {
  
  const store = createStore(reducer);
  
    return (
      &lt;Provider store={store}&gt;
        &lt;Layout /&gt;
      &lt;/Provider&gt;
    );
  }
  
  export default App;
  import React from 'react';
  import {Provider} from 'react-redux';
  import { createStore } from 'redux';
  import reducer from './store/reducer';
  import Layout from './layouts/main';
  import './app.css';
  function App() {
  
  const store = createStore(reducer);
  
    return (
      &lt;Provider store={store}&gt;
        &lt;Layout /&gt;
      &lt;/Provider&gt;
    );
  }
  
  export default App;
  </code></pre>
  
  <p>reducer.js</p>
  
  <pre><code>const initialState = {
      logged: false,
      user: null,
      empresas: null
  }
  
  const reducer = (state = initialState, action) =&gt; {
      switch(action.type) {
          case 'ONLOGIN': {
              return {
                  ...state,
                  user:action.user,
                  logged: true
              }
          }
          case 'ONLOGOUT': {
              return {
                  ...state, 
                  user: null,
                  logged: false
              }
          }
      }
  }
  
  export default reducer;
  </code></pre>
  
  <p>actions.js</p>
  
  <pre><code>
  const login = (user, logged)=&gt; {
      return {
          type:'ONLOGIN',
          user: user,
          logged: true
      }
  
  }
  
  
  export {login}
  </code></pre>