Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

React state has changed, but ui is not updated #22

Open
fengyun2 opened this issue Oct 22, 2016 · 0 comments
Open

React state has changed, but ui is not updated #22

fengyun2 opened this issue Oct 22, 2016 · 0 comments

Comments

@fengyun2
Copy link

React state has changed, but ui is not updated

  • platform verion

windows10

  • react-immutable-render-mixin version

0.9.7

  • code
import {shouldComponentUpdate} from 'react-immutable-render-mixin'
import ReactPullToRefresh from 'react-pull-to-refresh'

let count = 1
class Product extends Component {
  constructor(props) {
    super(props)
    this.shouldComponentUpdate = shouldComponentUpdate.bind(this)

    this.state = {
      items: [
        <div key={'item-' + count}>Item {count++}</div>
      ]
    }
  handleRefresh(resolve, reject) {
    let self = this
    console.log('handleRefresh...', this)
    setTimeout(function () {
      self.addItem() ? resolve() : reject()

      console.log('is true: ', self.addItem())
    }, 500)

  }
  addItem() {
    console.log('addItem...')
    this.state.items.push(<div key={'item-' + count}>Item {count++}</div>);
    this.setState({
      items: this.state.items
    })
    console.log('new items: ', this.state.items)
    return true
  }
  render() {
    return (
      <div className="content-block">

      <ReactPullToRefresh onRefresh={this.handleRefresh.bind(this)} style={{
        textAlign: 'center'
      }}>
        <h3>Pull down to refresh</h3>
        <div>
         {this.state.items}
        </div>
      </ReactPullToRefresh>
      </div>
    )
  }
}
  }

React state has changed, but ui is not updated when I add react-immutable-render-mixin

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant