K
K
Ken Jee2017-01-18 15:19:19
React
Ken Jee, 2017-01-18 15:19:19

How to properly connect React to the site?

There is HTML:

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

  <script src="https://unpkg.com/[email protected]/dist/react.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/react-dom.js"></script>

  <script src="https://unpkg.com/[email protected]/babel.js"></script>

        <script src="/r/b2b-spa/js/main.js"></script>

  <title>Тайтл</title>
</head>
<body>

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

</body>
</html>

Code inside /r/b2b-spa/js/main.js:
import React from 'react';
import ReactDOM from 'react-dom';

ReactDOM.render(
<h1>Hello, world!</h1>, document.getElementById('root')
);

There is an error on the first line of main.js:
Uncaught SyntaxError: Unexpected token import

Tell the newbie how to properly connect React JS to the page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-01-18
@Machez

In the documentation , one of the items you need is: A compiler such as Babel. It lets you write modern JavaScript code that still works in older browsers.
The browser "does not know how to import", so to speak. You need to run your ES2015 scripts through tools like babel .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question