Using Higher Order Components with Haunted
nirbG opened this issue · comments
gauthier brin commented
Hey guys, someone already tried to create a Higher Order Component with haunted? can you share with me some example, pls
gauthier brin commented
I might find a solution,
const hoc = (WrappedComponent) => (props) => {
// here I update my props with a custom hooks
const newProps = useProps(props);
return WrappedComponent(newProps);
};
it works well, I get the right props, but now "this" is undefined in my component.
I tried a lot of things but nothing works.
does anyone have any ideas on this?
Matthew Phillips commented
props is itself the element. You can do return WrappedComponent.call(newProps, newProps)
and it should have the correct this
.
gauthier brin commented
where the "call" function come from?
Matthew Phillips commented
All functions have a .call
function on them. It only works if the WrapperComponent is defined like function WrapperComponent()
and not const WrapperComponent = () =>
.