S
S
SannX2020-07-06 09:25:57
JavaScript
SannX, 2020-07-06 09:25:57

How to add react library to existing site?

I am creating a simple site without node.js but with react. I use this tutorial: https://ru.reactjs.org/docs/add-react-to-a-website... For react to work, it is advised to connect it via CDN:

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

<!-- Load React. -->
<script src="https://unpkg.com/[email protected]/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js" crossorigin></script>

<!-- Load your React component. -->
<script src="root.js"></script>

root.js is written with JSX syntax. Now I want to extend this example from the tutorial and add the react-csv-reader library . But how to do that? If it is imported inside root.js, then there will be an error "SyntaxError: import declarations may only appear at top level of a module". If you try to add it via CDN:
<!-- Load React. -->
<script src="https://unpkg.com/[email protected]/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js" crossorigin></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/react-csv-reader.min.js" crossorigin></script>

<!-- Load your React component. -->
<script src="root.js"></script>

then the error "ReferenceError: module is not defined" occurs. How to successfully add this library?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question