Kushal Jain
Kushal Jain

Reputation: 3186

Building an webapp using react native

I am building an webapp using react native. I am very new to react native. I started to build an simple page but its give an error. I don't know where I did wrong.

Screenshot of error

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>React Tutorial</title>
    <link rel="stylesheet" href="css/style.css" />
  </head>
  <body>
    <div id="header"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.1/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.0/JSXTransformer.js"></script>
    <script src="scripts/header.js"></script>

</body>
</html>

The above screenshot is of header.js. Where I did wrong could not understand. Help me out for any silly mistake. Thanks

Upvotes: 0

Views: 75

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74595

Your file header.js contains JSX, which the browser doesn't understand.

You need to transform your JSX file into JS before attempting to load it in the browser.

One way to do this is to include browser.js (from Babel) and add the attribute type="text/babel" to your JSX script.

Other options include using a tool such as Webpack with a loader that can pre-process your JSX before sending it to the client.

Upvotes: 1

Related Questions