1 2 3 4 |
@setTitle('Profile') class Profile extends React.Component { //.... } |
title is a string that will be set as a document title.
It is a parameter passed in from above (‘Profile’).
WrappedComponent is the Profile component displayed above.
Hence, @setTitle(title)(wrappedComponent) is what’s happening. We want to decorate the class Profile by returning a class
of our own with specific attributes and functionalities.
1 2 3 4 5 6 7 8 9 10 11 |
const setTitle = (title) => (WrappedComponent) => { return class extends React.Component { componentDidMount() { document.title = title } render() { return <WrappedComponent {...this.props} /> } } } |