ReactJS component names must begin with capital letters?!

来源:互联网 发布:安装ubuntu系统 编辑:程序博客网 时间:2024/05/21 00:16

http://stackoverflow.com/questions/30373343/reactjs-component-names-must-begin-with-capital-letters

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);

But as soon as I replace the fml with Fml it does render.

Is there a reason I cannot begin tags with small letters?


Answer:

In JSX, lower-case tag names are considered to be HTML tags. However, lower-case tag names with a dot (property accessor) aren't.

See HTML tags vs React Components.

  • <component /> compiles to React.createElement('component') (html tag)
  • <Component /> compiles to React.createElement(Component)
  • <obj.component /> compiles to React.createElement(obj.component)


0 0