ReactJS组件名称必须以大写字母开头吗? [英] ReactJS component names must begin with capital letters?
本文介绍了ReactJS组件名称必须以大写字母开头吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 JSBin 上使用ReactJS框架.
I am playing around with the ReactJS framework on JSBin.
我注意到,如果我的组件名称以小写字母开头,则不起作用.
I have noticed that if my component name starts with a lowercase letter it does not work.
例如,以下内容不呈现:
For instance the following does not render:
var fml = React.createClass({
render: function () {
return <a href='google.com'>Go</a>
}
});
React.render(<fml />, document.body);
但是只要我将fml
替换为Fml
,它就会渲染.
But as soon as I replace the fml
with Fml
it does render.
我有不能以小写字母开头的标签的原因吗?
Is there a reason I cannot begin tags with small letters?
推荐答案
在JSX中,小写标记名称被认为是HTML标记.但是,带有点(属性访问器)的小写标记名称不是.
In JSX, lower-case tag names are considered to be HTML tags. However, lower-case tag names with a dot (property accessor) aren't.
请参见 HTML标签vs React组件.
-
<component />
编译为React.createElement('component')
(html标记) -
<Component />
编译为React.createElement(Component)
-
<obj.component />
编译为React.createElement(obj.component)
<component />
compiles toReact.createElement('component')
(html tag)<Component />
compiles toReact.createElement(Component)
<obj.component />
compiles toReact.createElement(obj.component)
这篇关于ReactJS组件名称必须以大写字母开头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文