我正在使用Firebase child_added
列出数据。每当第一行被渲染时,onEndReached
被触发。我的代码有问题吗?反应原生onEndReached总是在第一行被渲染时触发
组件
onEndedReached() {
lastkey = Object.keys(this.props.contacts).pop();
// this.props.nextPage(this.props.auth.uid, lastKey);
console.log('Fire onEndedReached:', lastkey);
}
render() {
return (
<ListView
style={styles.container}
enableEmptySections
dataSource={this.dataSource}
renderRow={this.renderRow}
onEndReachedThreshold={50}
onEndReached={() => this.onEndedReached()}
/>
)
}
}
行动
export const getContacts = (uid) => {
return (dispatch) => {
firebase.database().ref(`userContacts/${uid}`)
.limitToFirst(20).on('child_added', (contact) => {
dispatch({
type: GET_CONTACTS_SUCCESS,
payload: { [contact.key]: contact.val() }
})
})
}
}
减速
const INITIAL_STATE = {};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case GET_CONTACTS_SUCCESS:
return Object.assign({}, state, action.payload);
default:
return state;
}
}
你使用滚动视图作为ListView的容器吗? –
编号我idid不使用 – vzhen
他们改变了> = 0.36版本的行为;当你不想让它触发时,只需在你的'onEndReached'函数中添加安全措施。 – Jan