We can decorate our class components, which is the same as passing the component into a function.
Decorators are flexible and readable way of modifying component functionality.
@setTitle('Profile')
class Profile extends React.Component {
//....
}
const setTitle = (title) => (WrappedComponent) => {
return class extends React.Component {
componentDidMount() {
document.title = title
}
render() {
return <WrappedComponent {...this.props} />
}
}
}