Last active
December 2, 2018 03:20
-
-
Save gaperton/540982e49830ee3521c03f4a464d0b79 to your computer and use it in GitHub Desktop.
afterRender( hook )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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