Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

this.state.targetItems carries outdated values when items prop changes #129

@umarashfaq

Description

@umarashfaq

Root cause:
When componentWillReceiveProps is invoked, this.props still carries previous version of props. New version of props is passed as a parameter to componentsWillReceiveProps.

Current implementation:

_initFromProps () {
    const targetItems = this._initSpyTarget(this.props.items)

    this.setState({
      targetItems,
    })

    this._spy(targetItems)
}

UNSAFE_componentWillReceiveProps () {
    this._initFromProps()
}

Proposed implementation:

_initFromProps (_props) {
    const props = _props ? _props : this.props;
    const targetItems = this._initSpyTarget(props.items)

    this.setState({
      targetItems,
    })

    this._spy(targetItems)
}

UNSAFE_componentWillReceiveProps (nextProps) {
    this._initFromProps(nextProps)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions