ReactJS component names must begin with capital letters?

后端 未结 5 1991
忘了有多久
忘了有多久 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:23

    The first part of a JSX tag determines the type of the React element, basically there is some convention Capitalized, lowercase, dot-notation.

    Capitalized and dot-notation types indicate that the JSX tag is referring to a React component, so if you use the JSX compile to React.createElement(Foo)
    OR
    compile to React.createElement(foo.bar) and correspond to a component defined or imported in your JavaScript file.

    While the lowercase type indicate to a built-in component like

    or and results in a string 'div' or 'span' passed to React.createElement('div').

    React recommend naming components with a capital letter. If you do have a component that starts with a lowercase letter, assign it to a capitalized variable before using it in JSX.

提交回复
热议问题