0

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

1
  • It's a requirement. It's mentioned in the React docs, if the warning you should be seeing in the JS console or transpiler isn't enough. Commented Feb 24, 2018 at 21:55

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Not just by convention. It's enforced.
That's correct, I was just quoting someone. I've referenced the documentation instead.
thank you all...my bad yes now i remember hearing instructor in the video say this.....but this is javascript or java crypt....
1

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

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

1 Comment

Some people might not use ES6 yet. reactjs.org/docs/react-without-es6.html
0

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 {

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.