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.

wrong compile result in jsx

See original GitHub issue

source

const Ob = (props) => {

  return <div>{props.r()}</div>
}

const App = () => {
  return <h2>
    hello
    <Ob r={() => {
      return <h1>zzzz</h1>
    }}/>
  </h2>
}

ReactDOM.render(
  <App/>,
  document.getElementById('root')
);

output:

"use strict";
const Ob = (props) => {

  return React.createElement("div", null, props.r())
}

const App = () => {
  return React.createElement("h2", null, "hello\r\n    ", 
            React.createElement(Ob, {r: true},    // =================> why ?
                React.createElement("h1", null, "zzzz")))
}

ReactDOM.render(
  React.createElement(App, null),
  document.getElementById('root')
);

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ilovedesert001commented, Sep 27, 2021

Thanks @ilovedesert001 for finding this and providing a good compact example.

I can confirm that this syntax is not yet handled so you can consider it a bug. I will do more testing to see if I can get a fix in (hopefully this week).

In the meantime, for reference moving the inline function outside of the Component will allow the code to compile.

const Ob = (props) => {
    return <div>{props.r()}</div>
}

function r() {
    return <h1>zzzz</h1>
}

const App = () => {
    return <h2>
        hello
        <Ob r={r}/>
    </h2>
}

ReactDOM.render(
    <App/>,
    document.getElementById('root')
);

Thanks for reply .

I think this project has huge potential. Especially when using in small/demo projects. i used htm.js before , Hope this is getting better and better

Thank you for implementing this library .

0reactions
ConradSollittcommented, Sep 28, 2021

Thanks and thanks for your help testing!

I just published a new release 5.10.3 that includes this fix. I gave you credit in the CHANGELOG.md file for finding and helping with this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React compile error using "create-react-app" - Stack Overflow
Save this question. Show activity on this post. I am suffering compile failure using "create-react-app".
Read more >
JSX In Depth - React
React Must Be in Scope​​ Since JSX compiles into calls to React. createElement , the React library must also always be in scope...
Read more >
Documentation - JSX - TypeScript
TypeScript supports embedding, type checking, and compiling JSX directly to ... but <bar /> will result in an error since it has not...
Read more >
8 common React error messages and how to address them
This warning will often present after you've made a habit of including a key prop with the resulting JSX from a list. import...
Read more >
@mdx-js/mdx | MDX
Whether to keep JSX ( boolean? , default: false ). The default is to compile JSX away so that the resulting file is...
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