-4

This is my code below, and when I tried to run it on localhost, nothing shows up, and in the console it says "Uncaught SyntaxError: Unexpected token <". (in line "

    const { render }=ReactDOM

    const style={
        backgroundColor:'orange',
        color:'white',
        fontFamily:'verdana'
    }



    render(
        <h1 id='title'
        className='header'
        style={style}>
        Hello World
        </h1>,
        document.getElementById('react-container')
    )

I checked several times but can't figure out what I did wrong. There is a index.html file and index.js file, above is the code from index.js file

cece
  • 67
  • 1
  • 1
  • 5

2 Answers2

0

You must import react to make use of JSX.

try to add this to the top of your code:

import React from 'react';
Pedro Mutter
  • 1,178
  • 1
  • 13
  • 18
0

Before everything, you must install the react dependency to your project. Install nodejs in your computer, then in the terminal, go to your project directory and run npm init. After you answer the questions, still inside your project folder, you need to run npm install --save react react-dom

Then, your final index.js code must look like this:

import React from 'react';
import ReactDOM from 'react-dom';

const style={
        backgroundColor:'orange',
        color:'white',
        fontFamily:'verdana'
    }

ReactDOM.render(<h1 id='title'
        className='header'
        style={style}>
        Hello World
        </h1>, document.getElementById('react-container'));
Pedro Mutter
  • 1,178
  • 1
  • 13
  • 18