| Start |
|---|
| Create React Component Let's explore the syntax differences by comparing two code examples. React.createClass (deprecated)Here we have a React.ComponentLet's take the above React.createClass definition and convert it to use an ES6 class. In this example we're now using ES6 classes. For the React changes, we now create a class called MyComponent and extend from React.Component instead of accessing React.createClass directly. This way, we use less React boilerplate and more JavaScript. PS: Typically this would be used with something like Babel to compile the ES6 to ES5 to work in other browsers. |
| "this" Context Using React.createClass will automatically bind React.createClassNote the React.ComponentWith ES6 classes There are a few ways we could bind the right Case 1: Bind inline:Case 2: Bind in the class constructorAnother approach is changing the context of Case 3: Use ES6 anonymous functionYou can also use ES6 anonymous function without having to bind explicitly: |
| Declare Default Props and PropTypes There are important changes in how we use and declare default props and their types. React.createClassIn this version, the React.ComponentThis version uses The Additionally, there is another syntax for |
| Mixins We can use React.createClassIn this version we can add React.ComponentReact mixins are not supported when using React components written in ES6. Moreover, they will not have support for ES6 classes in React. The reason is that they are considered harmful (opens new window). |
| Set Initial State There are changes in how we are setting the initial states. React.createClassWe have a React.ComponentIn this version we declare all state as a simple initialisation property in the constructor, instead of using the |
ES6/React “this” keyword with ajax to get data from server Syntax
Remarks
|
Read Article
https://develop.horje.com/learn/1434/reference