1

I would like to set up a React.js app only using either a local copy of the React.js scripts, or, only with the proper CDN links. React is registered only with CDN links, not with locally stored copies of React.js scripts. Why is that? Second, despite registering React while using only the CDN links, my element is not rendering. Why not? Do I have no choice but to use NPM to install everything?

<html>

<head>
    <meta charset="UTF-8">
    <title>First App</title>
</head>

<body>
    <div id="app"></div>

    <!-- This works (React is registering) -->
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>

    <!-- This doesn't (React is NOT registering) -->
    <!-- <script type="../scripts/react.development.js"></script> -->
    <!-- <script type="../scripts/react.dom.js"></script> -->

<script>
console.log('App.js is running!');
var Template = React.createElement(
  "h1",
  { id: "someid" },
  "This is JSX from app"
)
// Identifying the element by id
var AppRoot = document.getElementById('app')

ReactDOM.render(Template, AppRoot)

</script>
</html>
1

2 Answers 2

1

Ok, i run your code on my mashine, error really difficult to detect on first time. Your script attribute is type instead of src. There is correct variant:

<!-- This doesn't (React is NOT registering) -->
<script src="../scripts/react.development.js"></script>
<script src="../scripts/react.dom.js"></script>

If you download correct files it should be work.

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

Comments

0

Use <script src="../scripts/react.development.js"></script>

also please note ../ refers to the parent directory ./scripts if the scripts folder is in the same folder which contains the HTML

1 Comment

jsx needs to be transpiled to JS - not the puzzle piece that OP's asking about

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.