Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PureComponent<PropsType, StateType>

简单组件state,props对象只有一层改变使用,超过一层改变就会无法更新

constructor

Type parameters

Hierarchy

  • Component<PropsType, StateType>
    • PureComponent

Index

Constructors

constructor

Properties

Optional _children

_children: IComponentChild[]

react render 16 多node支持

Optional _component

子组件

_dirty

_dirty: boolean

是否加入更新队列

Optional _disable

_disable: undefined | false | true

是否停用

Optional _emitComponent

_emitComponent: Component<any, any>

模拟vue.emit用的上下文保存

Optional _key

_key: undefined | string

当前组件的key用于复用

Optional _nextVDom

_nextVDom: IVDom

被移除时的vdom缓存

Optional _parentComponent

_parentComponent: Component<IBaseProps, IKeyValue>

父组件

Optional _prevContext

_prevContext: IKeyValue

上一次的上下文

Optional _prevProps

_prevProps: PropsType

上一次的属性

Optional _prevState

_prevState: StateType

上一次的状态

Optional _ref

_ref: function | IRefObject

react标准用于设置component实例

Optional _renderCallbacks

_renderCallbacks: Array<function>

render 执行完后的回调队列

Optional _vdom

_vdom: IVDom

组件挂载后的vdom

Optional base

base: Node | Element | Text | null

context

context: IKeyValue

组件上下文,由父组件传递

Optional isFunctionComponent

isFunctionComponent: undefined | false | true

isPureReactComponent

isPureReactComponent: boolean = true

Optional name

name: undefined | string

自定义组件名

props

props: PropsType

由父级组件传递的状态,不可修改

state

state: StateType

当前组件的状态,可以修改

Static Optional defaultProps

defaultProps: IKeyValue

默认props

Methods

Optional componentDidMount

  • componentDidMount(): void

Optional componentDidUpdate

  • componentDidUpdate(previousProps: PropsType, previousState: StateType, snapshot: any, previousContext: IKeyValue): void
  • 在 render() 之后

    Parameters

    • previousProps: PropsType
    • previousState: StateType
    • snapshot: any
    • previousContext: IKeyValue

    Returns void

Optional componentWillMount

  • componentWillMount(): void

Optional componentWillReceiveProps

  • componentWillReceiveProps(nextProps: PropsType, nextContext: IKeyValue): void
  • 在新的 props 被接受之前 Use static getDerivedStateFromProps() instead

    deprecated

    Parameters

    • nextProps: PropsType
    • nextContext: IKeyValue

    Returns void

Optional componentWillUnmount

  • componentWillUnmount(): void

Optional componentWillUpdate

  • componentWillUpdate(nextProps: PropsType, nextState: StateType, nextContext: IKeyValue): void
  • 在 render() 之前,与 shouldComponentUpdate 互斥

    deprecated

    Parameters

    • nextProps: PropsType
    • nextState: StateType
    • nextContext: IKeyValue

    Returns void

forceUpdate

  • forceUpdate(callback?: undefined | function): void
  • 手动的同步更新dom

    Parameters

    • Optional callback: undefined | function

      回调

    Returns void

Optional getChildContext

Optional getSnapshotBeforeUpdate

  • getSnapshotBeforeUpdate(previousProps: PropsType, previousState: StateType, previousContext: IKeyValue): any

render

  • 用来生成VNode的函数,一定要继承后覆盖

    Parameters

    • props: PropsType
    • state: StateType
    • context: IKeyValue

    Returns childType

setState

  • setState(state: function | StateType, callback?: undefined | function): void
  • 设置state并通过enqueueRender异步更新dom

    Parameters

    • state: function | StateType

      对象或方法

    • Optional callback: undefined | function

      render执行完后的回调。

    Returns void

shouldComponentUpdate

  • shouldComponentUpdate(props: PropsType, state: StateType): boolean

Static Optional getDerivedStateFromProps

Generated using TypeDoc