深入浅出React和Redux——增加一个新的React组件

project Directory:

src/

public/

README.md

package.json

node_modules/


//entry file

src/index.js  

//render component app

ReactDom.render(

    ,

    document.getElementById('root')

//create components ClickCounter.js

import React, {component} from 'react';          //component as base class for all component provide common function

class ClickCounter extends component {

    constructor(props) {

        // invoking superClass constructed function

        super(props); 

        // binding instance object

        this.onClickButton = this.onClickButton.bind(this);

        // set init value

        this.state = {conut: 0}

    }

    onClickButton() {

        this.setState({count:this.state.count + 1});    

    }

    render() {

        return (   

           

               

               


                 Click Count: {this.state.count}

               


           


        );

    }

}

export default ClickCounter;

你可能感兴趣的:(React)