How can I add a button to a component using higher order component? I tried this but its not adding the button inside the component. Its adding it before the original component.
const withButton = WrappedComponent => {
return class extends Component {
render() {
return (
<Fragment>
<button>BUTTON ADDED USING HOC</button>
<WrappedComponent {...this.props} />
</Fragment>
)
}
}
}
export default withButton
When I call the HOF like this
const ComponentWithButton = withButton(WrappedComponent)
ComponentWithButton has button added but its adding before WrappedComponent whereas I want to add button inside as a child of the WrappedComponent.
Lets say that WrappedComponent is rendering something like
<div className="baseClass">{other divs and layout}</div>
const ComponentWithButton = withButton(WrappedComponent)
ComponentWithButton should render the following
<div className="baseClass">
<button>BUTTON ADDED USING HOC</button>
{other divs and layout}
</div>
<WrappedComponent {...this.props}><button>...</button></WrappedComponent>do what you want? Please, provide an example in case it doesn't.