Unexpected token < when using reactjs app

SomeGuyWhoCodes

I have been following a video tutorial which apparently using JSBin to show its code, when I tried out the code locally then it does not work for me. Could someone please help me to figure out what is the issue.

Below is the code

<!DOCTYPE html>
<html>

<head>
    <title>Redux basic example</title>
    <script src="https://unpkg.com/redux@latest/dist/redux.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react.min.js" type = "text/babel"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.0/react-dom.min.js" type = "text/babel"></script>
</head>

<body>
    <div id='root'>

    </div>
    <script>
        const counter = (state = 0, action) => {
            switch (action.type) {
                case 'INCREMENT':
                    return state + 1
                case 'DECREMENT':
                    return state - 1
                default:
                    return state
            }
        };

        const Counter = ({ value}) => (<div>{value}</div>);

        const { createStore } = Redux;
        var store = createStore(counter);

        const render = () => {
            ReactDOM.render(
                <Counter value={store.getState()} onIncrement = {
                    () => store.dispatch({type: 'INCREMENT'})
                } 
                onDecrement = {
                    () => store.dispatch({type: 'DECREMENT'})
                } />,
                document.getElementById('root')
            );
        };

        store.subscribe(render);
        render();
    </script>
</body>
</html>
Manolo Santos

The browser is complaining about the JSX code. You should transpile it to regular Javascript before including it in your page. There are several ways to do: Webpack, Babel...

Have a look to create-react-app npm package to get started fast: https://github.com/facebookincubator/create-react-app

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unexpected token error in reactjs app

From Dev

Unexpected token when using npm run dev on NextJS app

From Dev

Using Reactjs with electronjs getting unexpected token '<' error

From Dev

Unexpected token when using map

From Dev

React app with Typescript, Using generic spread expressions throw Unexpected token when trying to run the app

From Dev

Reactjs: Unexpected token, expected ","

From Javascript

ReactJS randomly Unexpected token '<'

From Dev

Reactjs with JSX: Unexpected token '<'

From Dev

reactjs Unexpected token '<'

From Dev

ReactJS: unexpected token '<'

From Dev

reactjs Unexpected token, expected ","

From Dev

Unexpected token, expected ";" in reactjs

From Dev

SyntaxError: Unexpected token '?' when creating new app using electron-forge

From Dev

Unexpected Token @ when using babel decorator

From Dev

React "return" unexpected token when using babelify

From Dev

Jquery unexpected token when using a function

From Dev

unexpected token import when using Mocha with Babel

From Dev

Uncaught SyntaxError: Unexpected token . when using ClassNotty

From Dev

Unexpected token "." when using .bind() in JavaScript

From Dev

Unexpected token "indent" when using Pug templates

From Dev

Parsing error: Unexpected token .. when using eslint

From Dev

Unexpected token error when using ionic/cordova

From Dev

"Unexpected Token" when using the map function in React

From Dev

Unexpected token error when using PHP with JavaScript

From Dev

ReactJS - Unexpected token when declaring a variable in component class

From Dev

Using ReactJS with npm and its giving following error(Unexpected token)

From Dev

Using async await on ReactJS with Babel leads to Error: Unexpected token

From Dev

ReactJS Unexpected Token ) on Safari only

From Javascript

ReactJS: "Uncaught SyntaxError: Unexpected token <"

Related Related

  1. 1

    Unexpected token error in reactjs app

  2. 2

    Unexpected token when using npm run dev on NextJS app

  3. 3

    Using Reactjs with electronjs getting unexpected token '<' error

  4. 4

    Unexpected token when using map

  5. 5

    React app with Typescript, Using generic spread expressions throw Unexpected token when trying to run the app

  6. 6

    Reactjs: Unexpected token, expected ","

  7. 7

    ReactJS randomly Unexpected token '<'

  8. 8

    Reactjs with JSX: Unexpected token '<'

  9. 9

    reactjs Unexpected token '<'

  10. 10

    ReactJS: unexpected token '<'

  11. 11

    reactjs Unexpected token, expected ","

  12. 12

    Unexpected token, expected ";" in reactjs

  13. 13

    SyntaxError: Unexpected token '?' when creating new app using electron-forge

  14. 14

    Unexpected Token @ when using babel decorator

  15. 15

    React "return" unexpected token when using babelify

  16. 16

    Jquery unexpected token when using a function

  17. 17

    unexpected token import when using Mocha with Babel

  18. 18

    Uncaught SyntaxError: Unexpected token . when using ClassNotty

  19. 19

    Unexpected token "." when using .bind() in JavaScript

  20. 20

    Unexpected token "indent" when using Pug templates

  21. 21

    Parsing error: Unexpected token .. when using eslint

  22. 22

    Unexpected token error when using ionic/cordova

  23. 23

    "Unexpected Token" when using the map function in React

  24. 24

    Unexpected token error when using PHP with JavaScript

  25. 25

    ReactJS - Unexpected token when declaring a variable in component class

  26. 26

    Using ReactJS with npm and its giving following error(Unexpected token)

  27. 27

    Using async await on ReactJS with Babel leads to Error: Unexpected token

  28. 28

    ReactJS Unexpected Token ) on Safari only

  29. 29

    ReactJS: "Uncaught SyntaxError: Unexpected token <"

HotTag

Archive