Skip to content

Instantly share code, notes, and snippets.

@ldong
Last active October 15, 2020 14:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldong/8ee85194274321454af2962b9794b38d to your computer and use it in GitHub Desktop.
Save ldong/8ee85194274321454af2962b9794b38d to your computer and use it in GitHub Desktop.
Ember vs React LifeCycle

Life Cycle Comparsion of Ember and React

React Hook Ember Hook Server? Initial Render? Rerender? Purpose
componentWillMount init Yes Yes No Set initial component state without triggering re-render
componentDidMount didInsertElement No Yes No Provides opportunity for manual DOM manipulation
componentWillReceiveProps willReceiveAttrs No No Yes React to changes in component attributes, so that setState can be invoked before render
shouldComponentUpdate Maybe N/A No No Yes Gives a component an opportunity to reject downstream revalidation
componentWillUpdate willUpdate No No Yes Invoked before a template is re-rendered to give the component an opportunity to inspect the DOM before updates have been applied (example)
componentDidUpdate didUpdate No No Yes Invoked after a template is re-rendered to give the component an opportunity to update the DOM (example)
componentWillUnmount willDestroyElement No No Yes The inverse of componentDidMount/didInsertElement; clean up anything set up in that hook
N/A willRender No Yes Yes In Ember, executed both after init and after willUpdate*
N/A didRender No Yes Yes In Ember, executed both after didInsertElement and didUpdate*
  • These hooks can be used in cases where the setup for initial render and subsequent re-renders is idempotent (e.g. $().addClass) instead of duplicating the logic in both places. In most cases, it is better to try to make these hooks idempotent, in keeping with the spirit of "re-render from scratch every time".

Quote from Implement Glimmer Engine by wycats · Pull Request #10501 · emberjs/ember.js Source

@ldong
Copy link
Author

ldong commented Sep 29, 2016

Other references

  1. ksnyde/ember-lifecycle-hooks: A visual for LifeCycle hooks in Ember (post and pre-glimmer)
  2. ember-website/ember-data-lifecycle.md at master · devinus/ember-website
  3. Ember Low level APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment