Skip to content

Instantly share code, notes, and snippets.

@gaperton
Last active December 2, 2018 03:20
Show Gist options
  • Save gaperton/540982e49830ee3521c03f4a464d0b79 to your computer and use it in GitHub Desktop.
Save gaperton/540982e49830ee3521c03f4a464d0b79 to your computer and use it in GitHub Desktop.
afterRender( hook )
const AfterRenderMixin = {
componentDidMount : callAfterRenderHooks,
componentDidUpdate : callAfterRenderHooks,
afterRender( hook ){
const { _callAfterRender } = this;
this._callafterRender = _callAfterRender ? () => {
_callAfterRender();
hook();
} : hook;
}
}
function callAfterRenderHooks(){
if( this._callAfterRender ){
this._callAfterRender();
this._callAfterRender = null;
}
}
class HookedComponent extends React.Component {
}
Object.assign( HookedComponent.prototype, AfterRenderMixin );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment