How to get index.html & index.js to render in MAMP on Mac?

I'm trying to use http://localhost:8888/ (MAMP) to render my index.html & index.js files within htdocs

index.html:

import React from 'react';

import ReactDOM from 'react-dom';

ReactDOM.render(<p>Hello</p>, document.getElementById('root'));

index.js:

<!DOCTYPE html>

<html lang="en">

  <head>

    <meta charset="utf-8" />

    <meta name="viewport"

      content="width=device-width, initial-scale=1" />

    <title>React App</title>

  </head>

  <body>

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

  </body>

</html>

I would assume they should be connected via 'root' and should display 'Hello' but it doesn't, it just displays a white screen.

Please let me know what I'm doing wrong

Tags:

HTML

React

JS

Node.js

MAMP

localhost

8888

1 Answer

Relevance
  • Anonymous
    1 month ago

    You've got it backwards. Start with a plain index.html that contains nothing but HTML. Get the server to deliver that. Then add the Javascript.

    Source(s): "Add React to a Website" https://reactjs.org/docs/add-react-to-a-website.ht...
    • Commenter avatarLog in to reply to the answers
Still have questions? Get answers by asking now.