Reputation: 146
How to import a component in a script in HTML file?
What are the modifications to be done to make the following work?
And should the Babel libraries be added to the HTML file? (Webpack and React are already installed)
In car.js
class Car extends React.Component {
render() { return (<p>nice car</p>) }}
In page.html
...
<script type="text/babel">
import Car from "static/car.js" //<---------????????
ReactDOM.render(<Car />, document.querySelector("#root"));
</script>
Upvotes: 1
Views: 496
Reputation: 4915
do not need to import Car from "static/car.js"
it will works in JS file.
for HTML need refarance like <script type="text/babel" src="static/car.js"></script>
<script src="static/car.js" type="text/babel"></script>
<script type="text/babel">
ReactDOM.render(<Car />, document.querySelector("#root"));
</script>
Upvotes: 2