Giter Site home page Giter Site logo

blog's Introduction

cytle.github.io

blog's People

Contributors

cytle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

blog's Issues

React打基础

React生命周期

  1. constructor
  2. componentWillMount 如果在这个函数里面调用setState,本次的render函数可以看到更新后的state,并且只渲染一次
  3. componentDidMount
  4. componentWillReceiveProps(nextProps) 父组件发生render的时候子组件就会调用componentWillReceiveProps(不管props有没有更新,也不管父子组件之间有没有数据交换)
  5. shouldComponentUpdate(object nextProps, object nextState) 每次调用setState后都会调用shouldComponentUpdate判断是否需要重新渲染组件
  6. componentWillUpdate
  7. componentDidUpdate
  8. render 不要在render里面修改state
  9. componentWillUnmount 一般在componentDidMount里面注册的事件需要在这里删除

如何触发render

假设shouldComponentUpdate返回true

  1. 第一次render
  • constructor
  • componentWillMount
  • render
  • componentDidMount
  1. 父组件render(无论props是否发生改变)
  • componentWillReceiveProps
  • shouldComponentUpdate
  • componentWillUpdate
  • render
  • componentDidUpdate
  1. setState(并非每次都触发render,多次会合并操作,TODO 怎么合并操作)
  • shouldComponentUpdate
  • componentWillUpdate
  • render
  • componentDidUpdate
  1. forceUpdate[1]
  • componentWillUpdate
  • render
  • componentDidUpdate

image

/**
 * ------------------ The Life-Cycle of a Composite Component ------------------
 *
 * - constructor: Initialization of state. The instance is now retained.
 *   - componentWillMount
 *   - render
 *   - [children's constructors]
 *     - [children's componentWillMount and render]
 *     - [children's componentDidMount]
 *     - componentDidMount
 *
 *       Update Phases:
 *       - componentWillReceiveProps (only called if parent updated)
 *       - shouldComponentUpdate
 *         - componentWillUpdate
 *           - render
 *           - [children's constructors or receive props phases]
 *         - componentDidUpdate
 *
 *     - componentWillUnmount
 *     - [children's componentWillUnmount]
 *   - [children destroyed]
 * - (destroyed): The instance is now blank, released by React and ready for GC.
 *
 * -----------------------------------------------------------------------------
 */

react 组件api

setState(object nextState[, function callback])

replaceState(object nextState[, function callback])

forceUpdate([function callback])

DOMElement getDOMNode()

bool isMounted()

setProps(object nextProps[, function callback])

replaceProps(object nextProps[, function callback])

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.