Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Higher Order Components with Haunted #225

Open
nirbG opened this issue Feb 6, 2021 · 5 comments
Open

Using Higher Order Components with Haunted #225

nirbG opened this issue Feb 6, 2021 · 5 comments
Labels
question Further information is requested

Comments

@nirbG
Copy link

nirbG commented Feb 6, 2021

Hey guys, someone already tried to create a Higher Order Component with haunted? can you share with me some example, pls

@nirbG
Copy link
Author

nirbG commented Mar 22, 2021

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?

@matthewp
Copy link
Owner

props is itself the element. You can do return WrappedComponent.call(newProps, newProps) and it should have the correct this.

@matthewp matthewp changed the title Someone already tried to create a Higher Order Component with haunted Using Higher Order Components with Haunted Mar 23, 2021
@matthewp matthewp added the question Further information is requested label Mar 23, 2021
@nirbG
Copy link
Author

nirbG commented Mar 23, 2021

where the "call" function come from?

@matthewp
Copy link
Owner

matthewp commented Mar 23, 2021

All functions have a .call function on them. It only works if the WrapperComponent is defined like function WrapperComponent() and not const WrapperComponent = () =>.

@matthewp
Copy link
Owner

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants