简体   繁体   English

反应js意外令牌错误

[英]react js unexpected token error

I am a new one who is learning react, i am also not familiar with JavaScript. 我是一个正在学习反应的新手,我也不熟悉JavaScript。 This is the 1 week that i am trying to import react. 这是我要导入的1周反应。 I added CDN script tag into my index.html at last. 最后,我将CDN脚本标记添加到了index.html中。

normally i can add xml tag into js files, but when i try to create component, system returns error. 通常我可以将xml标签添加到js文件中,但是当我尝试创建组件时,系统返回错误。

can anyone explain me what is my mistake? 谁能解释我的错误?

here is the index.html and my code. 这是index.html和我的代码。

index.html

app.js

错误

I have no idea what is going on when i try to write React.blabla, how system finds React components and how system imports it. 我不知道当我尝试编写React.blabla时发生了什么,系统如何找到React组件以及系统如何导入它。 i am familiar to Java. 我对Java很熟悉。 thanks in advance. 提前致谢。

in line 14, {} is an object. 在第14行中,{}是一个对象。 A property in an object has a name an a value: 对象中的属性具有名称和值:

{name: value}

However, your object has only the value but no name 但是,您的对象只有值,没有名称

{formatName(user)}
const element = React.createElement(
  'h1',
  {className: 'button'},
  formatName(user)
);

See here: https://codesandbox.io/s/myvm10lj5y 看到这里: https : //codesandbox.io/s/myvm10lj5y

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM