Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Created April 25, 2021 04:36
Show Gist options
  • Save sabesansathananthan/4222427abdc6007ba470a9f8d5fd6152 to your computer and use it in GitHub Desktop.
Save sabesansathananthan/4222427abdc6007ba470a9f8d5fd6152 to your computer and use it in GitHub Desktop.
How React Components Are Reused
function logProps(InputComponent) {
InputComponent.prototype.componentDidUpdate = function(prevProps) {
console.log("Current props: ", this.props);
console.log("Previous props: ", prevProps);
};
// Return the original input component, which has been modified.
return InputComponent;
}
// Every time logProps is called, the enhanced component will have log output.
const EnhancedComponent = logProps(InputComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment