{"action":"closed","issue":{"url":"https://api.github.com/repos/reactjs/redux/issues/1901","repository_url":"https://api.github.com/repos/reactjs/redux","labels_url":"https://api.github.com/repos/reactjs/redux/issues/1901/labels{/name}","comments_url":"https://api.github.com/repos/reactjs/redux/issues/1901/comments","events_url":"https://api.github.com/repos/reactjs/redux/issues/1901/events","html_url":"https://github.com/reactjs/redux/issues/1901","id":172264280,"number":1901,"title":"How to decouple a Component from it's own data fetching needs.","user":{"login":"Moezalez","id":8615251,"avatar_url":"https://avatars.githubusercontent.com/u/8615251?v=3","gravatar_id":"","url":"https://api.github.com/users/Moezalez","html_url":"https://github.com/Moezalez","followers_url":"https://api.github.com/users/Moezalez/followers","following_url":"https://api.github.com/users/Moezalez/following{/other_user}","gists_url":"https://api.github.com/users/Moezalez/gists{/gist_id}","starred_url":"https://api.github.com/users/Moezalez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Moezalez/subscriptions","organizations_url":"https://api.github.com/users/Moezalez/orgs","repos_url":"https://api.github.com/users/Moezalez/repos","events_url":"https://api.github.com/users/Moezalez/events{/privacy}","received_events_url":"https://api.github.com/users/Moezalez/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-20T10:13:54Z","updated_at":"2016-08-20T17:57:05Z","closed_at":"2016-08-20T17:57:05Z","body":"When a component requires a certain set of data to be fetched before rendering, I usually do something along those lines:\r\n\r\n```JavaScript\r\nclass Comp extends Component {\r\n  componentWillMount() {\r\n    this.props.requestData() // triggeres in action in the wrapper\r\n  }\r\n  render() {\r\n    const { data } = this.props.\r\n    return (\r\n       <div>\r\n         {/* do something with data */}\r\n       </div>\r\n    )\r\n  }\r\n}\r\n\r\nexport default connect(mapStateToProps, mapDispatchToProps)(Comp)\r\n```\r\n\r\nNow I have two React SPA's in which I want to use this component. In one App the needed data needs to be fetched before the component is mounted, in another the data already exists. \r\nSo I was wondering, if there is any best practice regarding the issue of fetching data that is a prerequisite for a component.\r\nIs there a way for the wrapper to listen to `Comp`'s lifecycle? Should I just rename  `requestData` to `onComponentWillMount` and listen to that for action triggering? "}}
{"actor":{"display_login":"markerikson"}}