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

Arrow functions are converted to traditional functions #215

Open
ghost opened this issue Oct 18, 2017 · 3 comments
Open

Arrow functions are converted to traditional functions #215

ghost opened this issue Oct 18, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Oct 18, 2017

Hi, I have the following component:

<Button onClick={e => console.log(e)}>Click me</Button>

But it is transformed to this instead:

<Button
  onClick={function onClick(e) {
                return console.log(e);
            }}
>
  Click me
</Button>

This cast is not only visually bad, it also changes the function behavior since an arrow function passes the this value from the context and not function. We might want to use "this" inside the callback function to alter the parent component state.

By the way, this library is very useful ! Thanks 👍

@armandabric
Copy link
Collaborator

Hi @mbeaudru-mrkl, thanks for your report

After some research it seems an arrow function could be lost if babel enter in the dance. Are your using it?

inspect-js/is-arrow-function#6

@tomc278
Copy link

tomc278 commented Jun 14, 2019

I am using babel and am getting this issue. What would be the best way around it?

@armandabric
Copy link
Collaborator

Expect not using Babel, there nothing you can do to avoid the transformation

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

No branches or pull requests

2 participants