After transpiling this code doesn't work
import React from 'react';
import ReactDOM from 'react-dom';
import firstLow from './moniesApp.js';
ReactDOM.render(<firstLow />, document.getElementById('content'));
but this does
import React from 'react';
import ReactDOM from 'react-dom';
import FirstHigh from './moniesApp.js';
ReactDOM.render(<FirstHigh />, document.getElementById('content'));
in first case babel produces
_reactDom2.default.render(_react2.default.createElement('firstLow', null), document...
and on page there is an empty <firstLow data-reactroot><firstLow/>
element rendered.
And in second case
_reactDom2.default.render(_react2.default.createElement(_moniesApp2.default, null), document...
and it works. My component is rendered.
What's going on?
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.
No. JavaScript variables cannot begin with numbers. Show activity on this post.
Disadvantage of ReactJSThey need to be always updated with their skills and learn new ways of doing things. It is another cons which are common for constantly updating technologies. React technologies updating and accelerating so fast that there is no time to make proper documentation.
There are a few good use cases for refs: Managing focus, text selection, or media playback. Triggering imperative animations. Integrating with third-party DOM libraries.
What's going on?
This is a convention in JSX/React. Lower case names are converted to strings (tags), capitalized names are resolved as variables (components).
From the docs:
Caveat:
Always start component names with a capital letter.
For example,
<div />
represents a DOM tag, but<Welcome />
represents a component and requiresWelcome
to be in scope.
In React, Component
names start with capital letters. Lower-case JSX tags represent literal HTML tags. This is part of the React specification.
This is why <foo>
is translated to createElement('foo')
, while <Foo>
yields createElement(module.Foo)
.
You should name your components with capital letters. Not much else to do.
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