I am using react.js without node.js, and I want to link multiple script files in my html file but i can't.
Basically, this is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" type="image/png" href="src/reactFavicon.png">
<link href="https://fonts.googleapis.com/css?family=Ma+Shan+Zheng|Righteous&display=swap" rel="stylesheet">
<title>Users</title>
<script type="application/javascript" src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script type="application/javascript" src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>
<script type="application/javascript" src="https://unpkg.com/[email protected]/babel.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
const rootElement = document.getElementById('root')
class Users extends React.Component {
constructor(props) {
super(props)
this.state = {
items:[],
isLoaded: false
}
}
componentDidMount() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items: json
})
})
}
render() {
const title = this.props.title;
var {isLoaded, items} = this.state;
if(!isLoaded) {
return <div>Loading...</div>
} else {
return(
<div class="Users">
{title}
<ul>
{items.map(item => (
<li key={item.id}>
{item.name} | {item.email} ||| lives in {item.address.street}, {item.address.suite} ({item.address.city}), his/her phone number is {item.phone} and works in <strong>{item.company.name}</strong>.
</li>
)) }
</ul>
</div>
)
}
}
}
function App() {
return (
<div>
<Users
title = "Users"
/>
</div>
)
}
ReactDOM.render(
<App />,
rootElement
)
</script>
</body>
</html>
And I want to separate the script file (text/babel) to a separate file and link it to the html, but that doesn't work despite VS Code not showing any error, I don't know what to do, I can't use Node (they don't use it in my work, nothing I can do).
This is the code that doesn't work:
<body>
<div id="root"></div>
<script type="text/babel" src="users.js"></script>
<body>
You can also use this example:
https://dev.to/luispa/lets-try-react-without-nodejs-3a7
Just like that, but with the script separated and linked/referenced in the html file, please help me...