kogibail
kogibail

Reputation: 135

Reactjs lowercase variable name for class name does not work?

I am new to ReactJS : i declare class like

var quiz=React.createClass{}..

this won't work unless I change the variable to Quiz..only then it will work. I am wondering is this requirement or may be I am missing out something? I am using jsx and coding in sublime text

Upvotes: 0

Views: 1332

Answers (3)

pankaj
pankaj

Reputation: 93

Actually this the fundamental of React that you should not name your component starting with smaller case letter.

This is how the react render method figure out that this is a user-defined component or predefined tag's.

consider an example.

suppose you have made a component called img for getting Image on the page and you name that component in a smaller case then render method will get not take your component but it will render normal HTML img tag

so it you want to correct it you have name it as Img.

In your case, you can do like this

const Quiz = () =>{

}

or

class Quiz extends React.Component {

}

Upvotes: 0

Singh
Singh

Reputation: 1988

React class names should start with a capital letter. Also, try creating class like so:

class Quiz extends React.Component{
   // your code here
}

Upvotes: 1

Charles Owen
Charles Owen

Reputation: 2900

In React, all components must have capital names, but your .jsx file can be lower case.

Here is the ReactJS documentation:

https://reactjs.org/docs/components-and-props.html

Always start component names with a capital letter. React treats components starting with lowercase letters as DOM tags. For example, represents an HTML div tag, but represents a component and requires Welcome to be in scope.

Upvotes: 2

Related Questions