-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
How to consume Decorator Components in ES6 #925
Comments
so decorators are just functions with special syntax that invokes them for you, but they're very easy to unwind and call yourself. your "read me" link above links to two issues that provide acceptable workarounds for decorators in environments that don't support them. this is the easiest way. |
should be along the lines of |
I tried both ways and none of them work.
Below is my
|
In this file hotkeysTarget.tsx If we add Then we can use this component as I tried modifying the dist file directly in node modules and it worked. So I think it should work when we modify .tsx and re-run the build. I modified this file. |
it looks like the decorator impl actually modifies the component prototype. this is a side effect, but it's always worked fine as a decorator. class Component ... {}
HotkeysTarget(Component);
// done. Component is now augmented to support `renderHotkeys`. feel free to submit a PR with the return statement if you want that usage. |
@giladgray we can consume decorators in bluprintJS as below.
Ideally HOF should not mutate the original passed argument, but in this case they are. |
huh, yeah, this is a bit strange and I didn't realize our hotkeys components did this. It's not how higher order components typically work, so we should consider refactoring HotkeysTarget and deprecating the existing API. |
@adidahiya |
Also ran into this issue and worked around it but would love to see the HOCs not mutate the component but return a new one for composing with Redux connect etc |
closing as we've resolved how to use invoke decorator functions directly and filed #931 to track mutation issue. |
@giladgray when I try use ContextMenuTarget, instead of a decorator I wrap the component like so:
but i get this error:
I'm importing ContextMenuTarget like this:
Do you have any idea why this isn't working? |
@jennykortina because ContextMenuTarget(Component);
// at this point, Component's prototype has been modified by the decorator
export default connect(null, dispatcher)(Component); The proper long-term fix is #931. |
@adidahiya thank you! |
Hello guys! I have the same issue as @veenedu (@HotkeysTarget-decorated class should implement renderHotkeys), and I am using exactly the same code as he mentioned. It also seems it has been fixed but as of version 3.6.1, I still have the issue. Is there something I should know? Since googling about this issue brings to this page, it would be nice to have a clear and defined conclusion :) Thank you. |
Hi,
I am using blueprintjs with facebook's create-react-app . I want to consume blueprint's HotkeysTarget. As per docs we have to add decorator to our Component class.
As of now create-react-app doesn't support decorators, read me
So how can I use HotkeysTarget and similar other component
The text was updated successfully, but these errors were encountered: