Showing posts with label React.Components. Show all posts
Showing posts with label React.Components. Show all posts

Sunday, June 11, 2017

Creating React Components

You can create stateless or stateful React components.

Let's start with the simple things first: the stateless components.

function MyStateLessComponent(props) {
         return <div />;  //See no quotes around the returning content
}

The same above in ES6:

MyStateLessComponent = (props)  => <div />

Now, to stateful components.

class MyStateFulComponent extends React.Component {
         constructor(props) {
                super(props)
         }
         render() {
               return <div />
         }
}

Another way of creating the stateful component in React:

var MyStateFulComponent = React.createClass({
         constuctor: function(props){
             super(props)
         }, //See the comma here ---don't forget this while doing the createClass
         render: function(){
             return <div />
         }
})

https://facebook.github.io/react/docs/components-and-props.html

https://facebook.github.io/react/docs/components-and-props.html