question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Recursion on classes when a method is used as a prop (ie onClick)

See original GitHub issue

I stumble upon on a recursion issue, The following:


class App extends Component {
  onClick() {}
  render() {
    return <Box onClick={this.onClick} />;
  }
}

compiles to


class App extends _mobxJsx.Component {
    onClick() {}
    render() {
        return (0, _mobxJsx.createComponent)(Box, {
            get onClick() {
                return this.onClick
            }
        })
    }
}

Demo: https://codesandbox.io/s/mobx-counter-context-bug-forked-wp9m9?file=/index.js

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ryansolidcommented, Sep 23, 2020

Ok happy to say fixed in babel-plugin-jsx-dom-expressions v0.20.8. Let me know if you have any more issues.

0reactions
ryansolidcommented, Sep 22, 2020

Ok this is next on my list assuming I can do it easily enough. I want to get this in for my next minor release of my libraries but I don’t want it to delay the next Solid release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onClick change from class to function - Stack Overflow
props.onClick() everytime the component is rendered. The return value of this.props.onClick() would then be set as the onClick value.
Read more >
this - JavaScript | MDN
When a function is used as a constructor (with the new keyword), its this is bound to the new object being constructed, no...
Read more >
How to Use Recursion in React - freeCodeCamp
Recursion simply means calling the same function inside itself, or rendering a component inside the same component. What will happen is, the  ......
Read more >
Recursion and stack - The Modern JavaScript Tutorial
Recursion is a programming term that means calling a function from itself. Recursive functions can be used to solve tasks in elegant ways....
Read more >
JavaScript Tutorial: The Basics
Basic JavaScript Tutorial for the beginners.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found