Advertisement
Guest User

Untitled

a guest
Apr 27th, 2022
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. Install Node.js if you haven't already
  2. Create a folder
  3. Use
  4. npm init
  5. ...to create a project, filling in the answers to the questions it asks.
  6. Install vite, react, and react-dom:
  7. npm install vite react react-dom
  8. Create an index.html file (below).
  9. Create an index.jsx file with your React code (below).
  10. Modify package.json so the "scripts" section is:
  11. "scripts": {
  12. "dev": "vite dev",
  13. "build": "vite build"
  14. },
  15. Then run your code in dev mode:
  16. npm run dev
  17. or build a production package:
  18. npm run build
  19.  
  20. index.html:
  21.  
  22. <!doctype html>
  23. <html>
  24. <head>
  25. <meta charset="UTF-8">
  26. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  27. <title>Example</title>
  28. </head>
  29. <body>
  30. <div id="root"></div>
  31. <script type="module" src="./index.jsx"></script>
  32. </body>
  33. </html>
  34.  
  35. index.jsx:
  36.  
  37. import React from "react";
  38. import { createRoot } from "react-dom/client";
  39.  
  40. class App extends React.Component {
  41. constructor(props) {
  42. super(props);
  43. }
  44.  
  45. render() {
  46. return (
  47. <div>
  48. <h1>Hello World</h1>
  49. </div>
  50. );
  51. }
  52. }
  53.  
  54. createRoot(document.getElementById("root")).render(<App />);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement