ReactJS 组件名称必须以大写字母开头吗? [英] ReactJS component names must begin with capital letters?

查看:30
本文介绍了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.

例如以下不呈现:

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 标签对比 React 组件.

  • 编译为 React.createElement('component') (html 标签)
  • 编译为 React.createElement(Component)
  • 编译为 React.createElement(obj.component)
  • <component /> compiles to React.createElement('component') (html tag)
  • <Component /> compiles to React.createElement(Component)
  • <obj.component /> compiles to React.createElement(obj.component)

这篇关于ReactJS 组件名称必须以大写字母开头吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆