Git Product home page Git Product logo

react-study's Introduction

react-study

  1. React component create:
export class Counter extends React.component {
	render () {
      return <h1>counter: {this.props.counter}</h1>
    }
}
  1. Component lifecycle :

Mounting(装配) 1. constructor() 2. componentWillMount() 3. render() 4. componentDidMount()

export class Computer extends React.component {
    constructor(props) {
       super(props);
       this.state = {
         name: props.name
         price: props.price
       }
    }

    componentWillMount() {
    	// you can do rest call. called before render method 
    }
	render() { 

       return <h1>{this.props.name} spent my {this.props.price}</h1>
    }

    componentDidMount() {
    	//推荐在这个地方做异步的请求数据。 让后触发重绘页面。
    }
}

Updating (更新) by changes to props or state

  1. componentWillReceiveProps()
  2. shouldComponentUpdate()
  3. componentWillUpdate()
  4. render() 
  5. componentDidUpdate() 

Unmounting

  componentWillUnmount() 触发在组件被删除的时候。 
  1. 强制更新UI。

    1. setState()
    2. forceUpdate()
  2. class properties (类属性)

    1. defaultProps
    2. displayName
  3. 实例属性

    1. props
    2. state
  4. ref 来操作dom <input ref={(input)=> this.input = input}/> ref的值是个函数

  5. props.children 和容器类组件

    class Card extends Component {
        render () {
          return (
            <div className='card'>
              <div className='card-content'>
                {this.props.children}
              </div>
            </div>
          )
        }
    }
    
  6. prop-types npm install --save prop-types

    static propTypes = {
    comment: PropTypes.object
    }
    

appreix

React small book

react-study's People

Contributors

abelyanghw avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.