0

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

1 Answer 1

1

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.

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

6 Comments

can you just tell me how to do this ?
There are several different ways to do this, e.g. sitepoint.com/getting-started-react-jsx
I read this link and tried it out but problem is I want to add external script but in above link describe only to write js on the same page. Can you help me out.
As far as I can tell, you just need to include the script before your JSX one and add the attribute type="text/babel".
I do it like <script type="text/babel" src="scripts/header.js"></script> but it gives me an error of "browser.min.js:3 XMLHttpRequest cannot load file:///C:/Users/Kushal/scripts/header.js. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
|

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.