React Basics: Creating classes

Okay, so I finished Redux from the curriculum yesterday. I didn’t go further because I thought I learnt too much and I should practice these new skills before I go any further.
After much difficulty on Codepen I managed to run my React code. (Apparently, the compiler should be changed and external scripts React and ReactDOM should be added)

My question:
We were taught here to create components so,

class componentName extends React.Component {
                  whatever: whatever
                 return someJSX;

But I was looking at other people’s code on CodePen and they do it in a different way. Why’s that? Which is better? Are they two totally different things?
Other Coders did it so,

var someVar = React.createClass{

Hi @graven_whismas,

today we’re releasing React 15.5.0.

New Deprecation Warnings
The biggest change is that we’ve extracted React.PropTypes and React.createClass into their own packages. Both are still accessible via the main React object, but using either will log a one-time deprecation warning to the console when in development mode. This will enable future code size optimizations.

Adding new warnings is not something we do lightly. Warnings in React are not mere suggestions — they are integral to our strategy of keeping as many people as possible on the latest version of React. We never add warnings without providing an incremental path forward.

So while the warnings may cause frustration in the short-term, we believe prodding developers to migrate their codebases now prevents greater frustration in the future. Proactively fixing warnings ensures you are prepared for the next major release. If your app produces zero warnings in 15.5, it should continue to work in 16 without any changes.

When React was initially released, there was no idiomatic way to create classes in JavaScript, so we provided our own: React.createClass.

Later, classes were added to the language as part of ES2015, so we added the ability to create React components using JavaScript classes. Along with functional components, JavaScript classes are now the preferred way to create components in React.

Cheers and happy coding :slight_smile:

Wow. So I was taught the correct syntax.
Thank you!

1 Like