0 votes
in ReactJS by
Why should component names start with capital letter?

1 Answer

0 votes
by

If you are rendering your component using JSX, the name of that component has to begin with a capital letter otherwise React will throw an error as unrecognized tag. This convention is because only HTML elements and SVG tags can begin with a lowercase letter.

class SomeComponent extends Component {

 // Code goes here

}

You can define component class which name starts with lowercase letter, but when it's imported it should have capital letter. Here lowercase is fine:

class myComponent extends Component {

  render() {

    return <div />

  }

}

export default myComponent

While when imported in another file it should start with capital letter:

import MyComponent from './MyComponent'

Related questions

0 votes
asked Jul 17, 2021 in ArangoDB by sharadyadav1986
0 votes
asked Mar 2, 2020 in ReactJS by RShastri
...