Last active
September 13, 2017 15:46
-
-
Save MrDesjardins/8d7429c405a80a059452654d2c2866ac to your computer and use it in GitHub Desktop.
React-Router HOC
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
import * as React from "react"; | |
export function withLog<P>(Comp: React.ComponentClass<P> | React.StatelessComponent<P>): React.ComponentClass<P> { | |
return class WrappedComponent extends React.Component<P, {}> { | |
public render(): JSX.Element { | |
console.log("render"); | |
return <Comp {...this.props} />; | |
} | |
public componentDidMount() { | |
console.log("componentDidMount"); | |
} | |
public componentWillMount() { | |
console.log("componentWillMount"); | |
} | |
public componentDidUpdate() { | |
console.log("componentDidUpdate"); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is used this way:
<Route path={Routes.ABC} component={withLog(AbcComponent)} />