Skip to content

Instantly share code, notes, and snippets.

@dkarmalita
Last active March 2, 2021 07:30
Show Gist options
  • Save dkarmalita/eefdac1d3ab9356e30d63ce30975a3ca to your computer and use it in GitHub Desktop.
Save dkarmalita/eefdac1d3ab9356e30d63ce30975a3ca to your computer and use it in GitHub Desktop.
React in-browser setup 2021
/* global React, ReactDOM, document, SubComponent */
/*
eslint-disable
react/react-in-jsx-scope,
react/jsx-filename-extension,
react/jsx-one-expression-per-line,
no-useless-constructor,
react/prefer-stateless-function,
react/jsx-no-undef
*/
class MainReact extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<strong>app.js</strong> is loaded<br />
<SubComponent />
</div>
);
}
}
ReactDOM.render(<MainReact />, document.getElementById('root-react'));
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<!-- <link rel="stylesheet" href="css/styles.css?v=1.0"> -->
</head>
<body>
<div id="root-react"></div>
<!-- Load Babel -->
<!-- v6 <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- import react.js -->
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<!-- import react-dom.js -->
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"> </script>
<!-- import your JS/JSX files and add - type="text/babel" - otherwise babel wont parse it -->
<script type="text/babel" src="subcomponent.js"></script>
<script type="text/babel" src="app.js"></script>
</body>
</html>
/* global React */
/*
eslint-disable
react/react-in-jsx-scope,
react/jsx-filename-extension,
react/jsx-one-expression-per-line,
no-useless-constructor,
react/prefer-stateless-function,
react/jsx-no-undef,
no-unused-vars
*/
class SubComponent extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<span> SubComponent-is-working </span>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment