{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react/issues/3279","labels_url":"https://api.github.com/repos/facebook/react/issues/3279/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react/issues/3279/comments","events_url":"https://api.github.com/repos/facebook/react/issues/3279/events","html_url":"https://github.com/facebook/react/issues/3279","id":59196867,"number":3279,"title":"componentDidReceiveProps Please","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":26,"created_at":"2015-02-27T06:34:05Z","updated_at":"2015-12-13T09:44:04Z","closed_at":null,"body":"I would like to humbly request a componentDidReceiveProps hook, often times I would like to do something on both componentWillMount and componentWillReceiveProps, but because `this.props` hasn't been set yet I am forced to pass props around instead of reading directly from `this.props`.\r\n\r\n## Before New Hook\r\n\r\n```javascript\r\ncomponentWillMount() {\r\n  this.setup(this.props.id);\r\n}\r\n\r\ncomponentWillReceiveProps(next) {\r\n  this.setup(next.id);\r\n}\r\n\r\nsetup(id) {\r\n  UserActions.load(id);\r\n}\r\n```\r\n\r\n## After New Hook\r\n\r\n```javascript\r\ncomponentWillMount() {\r\n  this.setup();\r\n}\r\n\r\ncomponentDidReceiveProps() {\r\n  this.setup();\r\n}\r\n\r\nsetup() {\r\n  UserActions.load(this.props.id);\r\n}\r\n```\r\n\r\nIn this simple example it may seem like a small thing, but often times the passing of props runs deep and instead of conveniently referencing this.props one is forced to plumb the props throughout the component.\r\n\r\nPlease consider adding `componentDidReceiveProps` as a hook to leverage the same code that is leveraged in componentWillMount without forcing both to plumb props throughout the component."},"comment":{"url":"https://api.github.com/repos/facebook/react/issues/comments/164242407","html_url":"https://github.com/facebook/react/issues/3279#issuecomment-164242407","issue_url":"https://api.github.com/repos/facebook/react/issues/3279","id":164242407,"user":{"login":"me-andre","id":594548,"avatar_url":"https://avatars.githubusercontent.com/u/594548?v=3","gravatar_id":"","url":"https://api.github.com/users/me-andre","html_url":"https://github.com/me-andre","followers_url":"https://api.github.com/users/me-andre/followers","following_url":"https://api.github.com/users/me-andre/following{/other_user}","gists_url":"https://api.github.com/users/me-andre/gists{/gist_id}","starred_url":"https://api.github.com/users/me-andre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/me-andre/subscriptions","organizations_url":"https://api.github.com/users/me-andre/orgs","repos_url":"https://api.github.com/users/me-andre/repos","events_url":"https://api.github.com/users/me-andre/events{/privacy}","received_events_url":"https://api.github.com/users/me-andre/received_events","type":"User","site_admin":false},"created_at":"2015-12-13T09:44:04Z","updated_at":"2015-12-13T09:44:04Z","body":"@kmalakoff , the 3 points you talk about are connected with the API only in that you use the API when you encounter them. They aren't caused by a bad design.\r\n\r\nThe first problem you talk about is that lifecycle methods take different arguments. Well, that's perfectly natural - they serve different purposes. `componentWillReceiveProps` takes props not because the moon was full when this method was added - but because it's about receiving props which have not been yet assigned to the component. `props` are being passed only in methods where they (may) differ from `this.props`. This is actually a hint, not an issue.\r\nThe problem # 3 is that it's hard for you to decide which callback / approach to use. Well, that's not really a problem **until** the methods I talk above have the same signature. Once you have both `state` and `this.state`, `props` and `this.props` which are equal (read meaningless) in most methods, then you get entangled in spare options and alternatives.\r\nThe problem # 2 is about boilerplate code... well, React is a thin library - and it's beautiful, easy and strict because of that. If you want to make a wrapper which would simplify our lives and reduce the amount of code we write every day - why not do it? Publish it as your own `npm` that depends on `react` and you're done.\r\n\r\nRegarding \"there are too many lifecycle methods\" - not yet and won't ever be if you stop requesting new callbacks for which you don't have a technical need. Technical need is when you implement a complex component and in the middle of work you understand **there is absolutely no way** of doing it without some ugly hack. It's about \"I need something to get called at the time the component does X but there's no such method and I cannot add one, so I use setTimeout and hopefully it wouldn't land earlier then I need\". Not when you say \"oh, I got tired of writing props = this.props\".\r\n\r\nAnd one more thing...\r\nIn a well-designed React application, you don't need most of the methods we talk about or you use them very rarely. `getInitialState`, `componentWillMount`, `componentWillUnmount` suffice 99% of the time. In my current project which is a relatively large commercial app, `componentWillReceiveProps` is used **twice** throughout all the app. I would not use it at all, but our environment (read browser) is imperfect."}}