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

Code breaks #13

Open
CeoFred opened this issue Nov 15, 2019 · 6 comments
Open

Code breaks #13

CeoFred opened this issue Nov 15, 2019 · 6 comments

Comments

@CeoFred
Copy link

CeoFred commented Nov 15, 2019

Copied the whole code for a test and seems to be broken at the point where we try to do the actual work.
return (
<h1 onClick={() => setState(c => c + 1)}>
Count: {state}

)

At this point my browser says Uncaught SyntaxError: Unexpected token '<'at the point we want to render the html as JSX.

@CeoFred
Copy link
Author

CeoFred commented Nov 15, 2019

For on i feel there should be more to be done before the code works, the browser does not understand Component tags so it keeps throwing errors, i tried solving the issue above by using string literals
function Counter() {
const [state, setState] = Didact.useState(1)
return <h1 onClick=${() => setState(c => c + 1)}> Count: ${state} </h1>
}
This guy was clearly working till we encountered something else
const element =
this guy above which clearly threw same syntax errors

@eddyw
Copy link

eddyw commented Nov 17, 2019

No, the browser doesn't understand JSX, as explained in the blog posts, JSX needs to be transformed to function calls (React.createElement or Didact.createElement) by a transpiler (Babel or TS). If you want 0 setup, use parcel bundler to generate code and don't forgot to add:

/** @jsx Didact.createElement */

Before writing/adding JSX

@CeoFred
Copy link
Author

CeoFred commented Nov 17, 2019

How do i get started with parcel bundler?

@cnscorpions
Copy link

@CeoFred for webpack, @plugins/transform-react-jsx is a must. no idea about parcel :)

@harryheman
Copy link

The simplest way to transform JSX to JS using Babel is:

<div id="root"></div>

<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
  // Didact code here
</script>

@MuLoo
Copy link

MuLoo commented Nov 7, 2022

The simplest way to transform JSX to JS using Babel is:

<div id="root"></div>

<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
  // Didact code here
</script>

yes, this is the simplest way

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

5 participants