I am trying to create an HOC which makes a regular functional component »Touchable«.
So I have that an HOC like that:
const Touchable = (Component, handler) => {
const T = ({props, children}) => {
const Instance = React.createElement(
Component,
{
...props,
onTouchStart: (e) => handler.touchStart(e),
/*more listeners*/
}, children);
}
return T;
}
Another Component like so:
const Button = ({props, children}) => <div>…</div>;
export default Touchable(Button, {touchStart: () => {}});
Using this like so:
<Button>Hallo</Button>
results in (react developer Panel):
<Button onTouchStart={…}>
<div>…</div>
</Button>
But what I really would like to have is:
<Button>
<div onTouchStart={…}>…</div>
</Button>
I have tried to clone the Instance, but somehow I have no luck. How can I do that?