In this answer, we have shared how to create props proxy for HOC component in reactjs with an example. we can add or edit the props passed to the component using props proxy pattern like the following example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function HOC(WrappedComponent) { return class Test extends Component { render() { const newProps = { title: 'New Header', footer: false, showFeatureX: false, showFeatureY: true } return <WrappedComponent {...this.props} {...newProps} /> } } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.