1

I am just hosting hello world with react and get the message:

Uncaught SyntaxError: expected expression, got '< with react

my code looks like this:

<html>
   <head>
   </head>
   <body>
      <div id="root">
         <!-- This element's contents will be replaced with your component. -->
      </div>
      <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
      <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
      <script>
         console.log("test")
         
         ReactDOM
         .createRoot(document.getElementById('root'))
         .render(<h1>Hello, world!</h1>);
         
      </script>
   </body>
</html>
1
  • 1
    <h1>Hello, world!</h1> is JSX code. This is not understandable by the navigators. You must have a tool like webpack or other to compile the react code. Commented Apr 16, 2022 at 15:31

2 Answers 2

1

<h1>Hello, world!</h1> is jsx. You need babel to convert it to javascript.

Sign up to request clarification or add additional context in comments.

Comments

0

So, i added:

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

to make it work. I needed to understand, that i could use react without jsx or vs versa.

I also found this video, which explains the concepts of react very well imho: https://www.youtube.com/watch?v=SAIdyBFHfVU

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.