title: How can I access current redux state from useEffect?
body: <p>I have a list of objects ("Albums" in my case) fetched from the database. I need to edit these objects. 
  In the editing component in the useEffect hook I fire up the action for getting the needed album using it's ID. This action works. However in the same useEffect I am trying to fetch the changed by before fired action redux state. And now I face the problem - all I am fetching is the previos state. 
  How can I implement in the useEffect fetching of current redux state?</p>
  
  <p>I've seen similar questions here, however none of the answers were helpfull for my use case.</p>
  
  <p>I am using redux-thunk.</p>
  
  <p>Editing component. The problem appears in setFormData - it's fetching previous state from the reducer, not the current one. It seems that it fires before the state gets changed by the getAlbumById:</p>
  
  <pre><code>//imports
  
  const EditAlbum = ({
    album: { album, loading},
    createAlbum,
    getAlbumById,
    history,
    match
  }) =&gt; {
    const [formData, setFormData] = useState({
      albumID: null,
      albumName: ''
    });
  
    useEffect(() =&gt; {
      getAlbumById(match.params.id);
  
      setFormData({
        albumID: loading || !album.albumID ? '' : album.albumID,
        albumName: loading || !album.albumName ? '' : album.albumName
      });
  
    }, [getAlbumById, loading]);
  
  const { albumName, albumID } = formData;
  
    const onChange = e =&gt;
      setFormData({ ...formData, [e.target.name]: e.target.value });
  
    const onSubmit = e =&gt; {
      e.preventDefault();
      createAlbum(formData, history, true);
    };
  
    return ( //code );
  };
  
  
  
  EditAlbum.propTypes = {
    createAlbum: PropTypes.func.isRequired,
    getAlbumById: PropTypes.func.isRequired,
    album: PropTypes.object.isRequired
  };
  
  const mapStateToProps = state =&gt; ({
    album: state.album
  });
  
  export default connect(
    mapStateToProps,
    { createAlbum, getAlbumById }
  )(withRouter(EditAlbum));
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code>export const getAlbumById = albumID =&gt; async dispatch =&gt; {
    try {
      const res = await axios.get(`/api/album/${albumID}`);
  
      dispatch({
        type: GET_ALBUM,
        payload: res.data
      });
    } catch (err) {
      dispatch({
        type: ALBUMS_ERROR,
        payload: { msg: err.response.statusText, status: err.response.status }
      });
    }
  };
  </code></pre>
  
  <p>reducer </p>
  
  <pre><code>const initialState = {
    album: null,
    albums: [],
    loading: true,
    error: {}
  };
  
  const album = (state = initialState, action) =&gt; {
    const { type, payload } = action;
    switch (type) {
      case GET_ALBUM:
        return {
          ...state,
          album: payload,
          loading: false
        };
      case ALBUMS_ERROR:
        return {
          ...state,
          error: payload,
          loading: false
        };
      default:
        return state;
    }
  };
  </code></pre>
  
  <p>Will be grateful for any help/ideas</p>