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
Other references