当主屏幕加载时,我得到'不变违规:refreshing
道具必须设置为布尔值才能使用onRefresh
,但得到了undefined
'请帮助。
class Home extends Component {
constructor(props) {
super(props)
this.state = {
suggestionList:[],
refreshing:false,
};
}
componentWillReceiveProps(nextProps){
this.setState({
suggestionList: nextProps.result.suggestionsArray ,
lastSuggestionKey : nextProps.result.lastSuggestionKey,
refreshing : false
});
}
handleRowPress = (item) => {
this.props.navigation.navigate('UserDetails', item);
};
handleMoreRequest = () => {
this.props.getOld(this.state.lastSuggestionKey);
};
handleRefresh = () => {
this.setState({
lastSuggestionKey: '',
refreshing: true
});
this.props.getAll();
};
componentWillMount() {
this.props.getAll();
}
render() {
return (
<View style={styles.containerStyle}>
<FlatList
style={{backgroundColor: colors.background}}
data={this.state.suggestionList}
renderItem={(item) =>
<CardItem contact={item.item}
onPress={() => this.handleRowPress(item)}
onCommentPress={() => this.props.navigation.navigate('SuggestionList')}/>
}
keyExtractor={item => item.suggestionid}
refeshing={this.state.refreshing}
onRefresh={() => this.handleRefresh()}
onEndReached={this.handleMoreRequest}
onEndReachedThreshold={0.7}
/>
</View>
);
}
}
const styles = StyleSheet.create({
containerStyle:{
flex:1,
backgroundColor: colors.background
},
});
function mapStateToProps({ suggestion }) {
return {
result: suggestion.result,
};
}
export default connect(mapStateToProps, actions)(Home);
你的 FlatList 道具上有一个错别字,它应该是refreshing
而不是refeshing
。
我也经历过同样的事情,我发现这个问题是因为onRefresh
道具的使用必须与refreshing={condition}
道具的使用重合。
我遇到了同样的问题。显然,通过在 onRefresh 道具之前设置刷新道具,它起作用了。试一试。
`refreshing={refreshing}
onRefresh={() => {
setItem(sumItemsArray);
}}
/>