Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 在第二次加载后响应本机ListView数据源更新_React Native - Fatal编程技术网

React native 在第二次加载后响应本机ListView数据源更新

React native 在第二次加载后响应本机ListView数据源更新,react-native,React Native,我在react native中是新的,我没有什么问题,当我输入到组件数据时并没有加载,但在第二次输入后,我得到了所有数据。您是否选择了错误的生命周期来使用此功能 class Followers extends Component { componentWillMount() { this.props.followersFetch(); this.createDataSource(this.props) } componentWillReceiveProps(nex

我在react native中是新的,我没有什么问题,当我输入到组件数据时并没有加载,但在第二次输入后,我得到了所有数据。您是否选择了错误的生命周期来使用此功能

class Followers extends Component {

  componentWillMount() {
    this.props.followersFetch();
    this.createDataSource(this.props)
  }

  componentWillReceiveProps(nextProps) {
      this.createDataSource(nextProps)
  }

  createDataSource({followersList}) {
    const ds = new ListView.DataSource({
      rowHasChanged: (r1, r2) => r1 !== r2
    })
    this.dataSource = ds.cloneWithRows(followersList)
  }

  renderRow(event) {
    return (
      <User info = {info} />
    );

  }

  render() {
    return (

      <Container>
          <Content>
              <ListView
              enableEmptySections
              dataSource={this.dataSource}
              renderRow={this.renderRow}
              />
          </Content>
      </Container>
    );
  }
}

const  mapStateToProps = state  => {
  const followersList = _.map(state.relation.followersList, (val, uid) => {
      return {...val, uid}
  });

  return {followersList}
}

export default connect(mapStateToProps, {followersFetch})(Followers);
类跟随器扩展组件{
组件willmount(){
this.props.followersFetch();
this.createDataSource(this.props)
}
组件将接收道具(下一步){
this.createDataSource(nextProps)
}
createDataSource({followersList}){
const ds=new ListView.DataSource({
行已更改:(r1,r2)=>r1!==r2
})
this.dataSource=ds.cloneWithRows(followersList)
}
renderRow(事件){
返回(
);
}
render(){
返回(
);
}
}
常量mapStateToProps=状态=>{
const followersList=\ uu.map(state.relation.followersList,(val,uid)=>{
返回{…val,uid}
});
返回{followersList}
}
导出默认连接(mapstatetops,{followersFetch})(Followers);
我写错了什么?
我认为使用componentWillMount有问题?

尝试将此移动。数据源初始化为componentWillMount,类似于:

componentWillMount() {
  const ds = new ListView.DataSource({
    rowHasChanged: (r1, r2) => r1 !== r2
  })
  this.dataSource = ds.cloneWithRows(followersList)
}

你想达到什么目标?你的代码缺乏逻辑性