{"action":"created","issue":{"url":"https://api.github.com/repos/rackt/react-redux/issues/102","labels_url":"https://api.github.com/repos/rackt/react-redux/issues/102/labels{/name}","comments_url":"https://api.github.com/repos/rackt/react-redux/issues/102/comments","events_url":"https://api.github.com/repos/rackt/react-redux/issues/102/events","html_url":"https://github.com/rackt/react-redux/issues/102","id":106055537,"number":102,"title":"Passing State to Action Creators","user":{"login":"iammerrick","id":109635,"avatar_url":"https://avatars.githubusercontent.com/u/109635?v=3","gravatar_id":"","url":"https://api.github.com/users/iammerrick","html_url":"https://github.com/iammerrick","followers_url":"https://api.github.com/users/iammerrick/followers","following_url":"https://api.github.com/users/iammerrick/following{/other_user}","gists_url":"https://api.github.com/users/iammerrick/gists{/gist_id}","starred_url":"https://api.github.com/users/iammerrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iammerrick/subscriptions","organizations_url":"https://api.github.com/users/iammerrick/orgs","repos_url":"https://api.github.com/users/iammerrick/repos","events_url":"https://api.github.com/users/iammerrick/events{/privacy}","received_events_url":"https://api.github.com/users/iammerrick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-11T17:19:03Z","updated_at":"2015-09-11T17:23:55Z","closed_at":null,"body":"In the case where you need to read state in an action creator what is the best way to do so... For example suppose I have an action creator that gets a new user object:\r\n\r\n```javascript\r\nexport function load(state) {\r\n  return (dispatch) => {\r\n    if (getUser(state)) return null;\r\n\r\n    get()\r\n      .then((response) => {\r\n        dispatch({\r\n          type: AppConstants.USER_LOAD_SUCCESS,\r\n          payload: {\r\n            response\r\n          }\r\n        });\r\n      });\r\n  }\r\n} \r\n```\r\n\r\nNotice it is configured ahead of time with the current state, this enables the action creator to decide if it should really fire the action or not. Currently the mapping state and actions to components is separated, what do you do when an action creator needs access to state?\r\n\r\n```javascript\r\nexport default connect((state, props) => {\r\n  return {\r\n    user: getUser(state)\r\n  };\r\n}, (dispatch) => {\r\n  // I want state here to configure my action creator!\r\n  return {\r\n    load: () => dispatch(load(state))\r\n  }\r\n})(User);\r\n```"},"comment":{"url":"https://api.github.com/repos/rackt/react-redux/issues/comments/139606286","html_url":"https://github.com/rackt/react-redux/issues/102#issuecomment-139606286","issue_url":"https://api.github.com/repos/rackt/react-redux/issues/102","id":139606286,"user":{"login":"iammerrick","id":109635,"avatar_url":"https://avatars.githubusercontent.com/u/109635?v=3","gravatar_id":"","url":"https://api.github.com/users/iammerrick","html_url":"https://github.com/iammerrick","followers_url":"https://api.github.com/users/iammerrick/followers","following_url":"https://api.github.com/users/iammerrick/following{/other_user}","gists_url":"https://api.github.com/users/iammerrick/gists{/gist_id}","starred_url":"https://api.github.com/users/iammerrick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iammerrick/subscriptions","organizations_url":"https://api.github.com/users/iammerrick/orgs","repos_url":"https://api.github.com/users/iammerrick/repos","events_url":"https://api.github.com/users/iammerrick/events{/privacy}","received_events_url":"https://api.github.com/users/iammerrick/received_events","type":"User","site_admin":false},"created_at":"2015-09-11T17:23:55Z","updated_at":"2015-09-11T17:23:55Z","body":"How are others implementing fire and forget actions for incrementally loading data. Sprinkling the logic into every component and only firing conditionally? "}}