-2
我不知道如何解釋這個問題,但也許有人知道。現在我學習了React-native並發現了一些問題。爲什麼數據僅在第一次呈現在反應本地後才加載組件
如果我第一次打開某個組件,我沒有看到任何數據,但如果我這樣做第二次數據加載。
class Followers extends Component {
componentWillMount() {
const {uid} = this.props.user;
this.props.followersFetch({uid});
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(follower) {
return (<User follower={follower}/>);
}
render() {
return (
<Container>
<Content>
<ListView enableEmptySections dataSource={this.dataSource} renderRow={this.renderRow}/>
</Content>
</Container>
);
}
}
const mapStateToProps = state => {
console.log(state)
const {followersList} = state.relation;
const {uid} = state.profile;
return {uid, followersList}
}
export default connect(mapStateToProps, {followersFetch})(Followers);
I'm trying use ComponentDidMount for sure data is loading but it give me error