-
Notifications
You must be signed in to change notification settings - Fork 47.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify mount and update component life-cycle methods #2074
Comments
for me unify |
+1 @oriSomething In addition, isn't doing |
I'm not saying you're wrong, but at the heart, React works much like old-school server-rendered pages. Render page, click something, throw everything away, render page. In this model there is no separation between first and subsequent renders. Now that's obviously not exactly how React works in practice due to reconciliation, so there are obviously a need for But my curiosity lies in that my "proposed" change makes inconsistent/broken behavior less likely to occur as only listening to
Whereas with the old separation you can "easily" have inconsistencies:
I also think my proposed change makes it easier to understand how a component is implemented, as you no longer need to correlate the differences of PS. Again, I'm not forcefully pushing for this, but I think it's an interesting topic. |
Overall I agree with you, and honestly, there's something like a 50/50 split for me between having actually separate mount/update behavior and a shared method being called for both (outside of jQuery plugin wrapping). I think it'd be nice to try this idea out and see how it might work out for use cases that involve forcefully manipulating the DOM element. IIRC Ember components just do both where the mount methods are called and then the update method runs directly after them. I think doing this makes sense, but maybe it should be conditional definitions of mount methods that decides whether or not mount or update methods are called on component render. |
👍 for combining the methods and having |
I suggest React also run Usually this code does async data fetching according to a value given in props and change state after data is fetched. So both |
We might consider this in the future. Let's continue the discussion in #7678. |
Kind of related #2073
It seems to me there's a natural correlation between mount and update methods:
In many situations you want to have the same code for mount/update, but you have to put it in a shared method and call it from both places. It's hardly common enough that it's an issue, but it seems common enough that it strikes me as a bit odd... perhaps. Just an idea, could it make sense to e.g. get rid of mount altogether and instead have the following (it's extreme perhaps, but just as an example):
It would unify the life-cycle and move away from mounting being treated as entirely separate from updating, it would then be seen as an exception. There would be less potential for inconsistencies causes by mistake/neglect.
I haven't thought this through extensively and bring it up mainly to start a discussion, I know many others have wondered why there isn't a life-cycle method for mount+update.
The text was updated successfully, but these errors were encountered: