道具更新时如何防止React列表组件刷新?

时间:2016-09-28 11:15:16

标签: reactjs meteor

我有一个列表组件,它使用prop来修改订阅参数,以限制显示的结果。这工作正常,但是当我向列表中添加额外的5个结果时,我想阻止表完全刷新。这可能吗?目前我通过从父组件传递的方法更新道具。我把它包含在代码的底部。

任何建议表示赞赏!

export default class ListingTable extends TrackerReact(React.Component) {
  static propTypes = {
    LimitProp: React.PropTypes.number,
  }
  static defaultProps = {
    LimitProp: 5
  }

  constructor(props) {
    super(props);
    const subscription =  Meteor.subscribe("allLists",{sort: {_id:-1}, limit: this.props.LimitProp})
    this.state = {
      listData: subscription,
    }
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.LimitProp != nextProps.LimitProp) {
      // Stop old subscription
      this.state.eventsData.stop()
      // Setup new subscription
      const subscription = Meteor.subscribe("allLists",{sort: {_id:-1}, limit:       nextProps.LimitProp})
      this.setState({ listData: subscription })
    }
  }


  ...
  render() {
  ...
    <a className="item" onClick= {(event) => this.props.methodLoadMore(event)}>Load More</a>
    ...

  }

//this method is in the parent component, onClick Method calls this
loadMore(event) {
  event.stopImmediatePropagation
  event.preventDefault()

  var limit = this.state.listLimit;
  limit = limit + 5
  this.setState({listLimit: limit})
  FlowRouter.setQueryParams({limit: limit})
}

0 个答案:

没有答案