So, when you declare a component in react with a lowercase first letter, it doesn't show up, without throwing an error. When you capitalise the component name, it does work.
What is it implemented like this? To avoid collision with existing html elements, or is this a bug?
var test = React.createClass({
render: function() {
return (
<div>Test</div>
);
}
});
var Screen = React.createClass({
render: function() {
return (
<div>
<test/>
</div>
);
}
});
When I change test
to Test
, it works:
var Test = React.createClass({
render: function() {
return (
<div>Test</div>
);
}
});
var Screen = React.createClass({
render: function() {
return (
<div>
<Test/>
</div>
);
}
});
User-Defined Components Must Be Capitalized When an element type starts with a lowercase letter, it refers to a built-in component like <div> or <span> and results in a string 'div' or 'span' passed to React. createElement . Types that start with a capital letter like <Foo /> compile to React.
Using Pascal Case for Both File and Component Name In addition, it requires the first letter to be uppercase as well, while the camel case does not.
All React component names must start with a capital letter. If you start a component name with a lowercase letter, it will be treated like a built-in element like a <div> or a <span> . This is because of the way JSX works. In JSX, rendering a component that begins with a lowercase letter compiles down to React.
Therefore, your custom React components must either start with a capital letter or use the dot notation. If, for some reason, you have a React component that does start with a lowercase letter, then you should assign it to a capitalized variable before using it in JSX.
From some react release notes
the JSX tag name convention (lowercase names refer to built-in components, capitalized names refer to custom components).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With