1

I am creating a test React web application using documentation here in VS 2015 but I am getting error

Uncaught SyntaxError: Unexpected token <

my code

class CommentBox extends React.Component {
render() {
return (
  <div className="commentBox">
      Hello, world! I am a CommentBox.
  </div>
);
}
}

ReactDOM.render(
<CommentBox />,
document.getElementById('content')
);

enter image description here

enter image description here

the nuget package I have installed

enter image description here

3
  • React template are not support anymore. I get the same issue like this. You need to update to VS 2017 in order to use React in VS Commented Jul 16, 2018 at 4:12
  • This error is occurring in browser, how is this link to VS? Commented Jul 16, 2018 at 4:25
  • You using MVC 4 with react and to me that package is not need . The detail of package can be found at. In VS 2017 there is built in React & .Net template you can check that out. And main reason is you dont use babel to compile your code from ES6 to ES5 Commented Jul 16, 2018 at 4:31

1 Answer 1

2

in an image, a list of packages is for server-side rendering. you are trying to render as client side.

React.Web.MVC4 NuGet package is for server side. for example:

class CommentBox extends React.Component {
      render() {
         return (
            <div className="commentBox">
                Hello, {this.props.name}! I am a CommentBox.
            </div>
        );
    }
} /* Script/App.js */


@using React.Web.mvc

@Html.React("CommentBox",new{
    name="John"
})  /* Index.cshtml */


namespace MyApp
{
    public static class ReactConfig
    {
        public static void Configure()
        {
            ReactSiteConfiguration.Configuration = new ReactSiteConfiguration()
                .AddScript("~/script/App.js");
        }
    }
}  /* AppStart/reactConfig.cs */

react.js with mvc server side

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.