ReactJS component names must begin with capital letters?

后端 未结 5 2003
忘了有多久
忘了有多久 2020-11-22 04:56

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 instan

5条回答
  •  失恋的感觉
    2020-11-22 05:20

    @Alexandre Kirszenberg gave a very good answer, just wanted to add another detail.

    React used to contain a whitelist of well-known element names like div etc, which it used to differentiate between DOM elements and React components.

    But because maintaining that list isn't all that fun, and because web components makes it possible to create custom elements, they made it a rule that all React components must start with a upper case letter, or contain a dot.

提交回复
热议问题