我有一个FlatList渲染{this.state.groups},我想使用Redux重新渲染带有新组的多余数据。 我的减速机与新组一起很好地返回了道具,但是什么也没发生!
FlatList代码:
staging/src/k8s.io/kubectl/pkg/describe/describe.go
MapStateToProps:
<FlatList
keyExtractor={(item) => item.groupId.toString()}
data={this.state.groups}
extraData={this.props.newGroups}
renderItem={this.renderItem}
ItemSeparatorComponent={this.renderSeparatorView}
/>
减速器:
const mapStateToProps = (state) => {
return {
newGroups: state.newGroups
}
}
当我console.log()this.state.groups和this.props.newGroups时,我具有组Object的初始数组和具有新组的新Array:
function groupReducer(state = initialState, action) {
let nextState
switch (action.type) {
case 'ADD_GROUP':
nextState = {
...state,
newGroups: [...state.newGroups, action.value]
}
return nextState
default:
return state
}
}
编辑: 当我像这样更改flatList数据时:data = {this.props.newGroups},我得到了Reducer中的数据。 Redux运行良好。我认为问题来自FlatList中state.data和props.data的添加。
任何人都知道为什么它不起作用吗?