How you use decorators in React.js?

Answer

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} />
}
}
}

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---