ListView在状态更新后不呈现新项
我有一个React本地项目和Redux 我将组件注释嵌入到组件ParentComponent中 添加注释后,“我的注释”组件将接收更新的状态,并使用props中的新数组调用呈现函数。但是不要在listView上绘制新的单元格 我的ActionComments代码 添加注释:ListView在状态更新后不呈现新项,listview,reactjs,react-native,render,redux,Listview,Reactjs,React Native,Render,Redux,我有一个React本地项目和Redux 我将组件注释嵌入到组件ParentComponent中 添加注释后,“我的注释”组件将接收更新的状态,并使用props中的新数组调用呈现函数。但是不要在listView上绘制新的单元格 我的ActionComments代码 添加注释: if(parent_id){ commentsList[parent_index].responses.push(responseObject) }else{ commentsList.splice(0, 0, re
if(parent_id){
commentsList[parent_index].responses.push(responseObject)
}else{
commentsList.splice(0, 0, responseObject)
}
Actions.pop()
var newList = commentsList
dispatch(commentsListUpdate(newList))
评论列表更新:
function commentsListUpdate(list) {
return {
type: types.COMMENTS_LIST_UPDATE,
list
};
}
我的减速机:
case types.COMMENTS_LIST_UPDATE:
return {
...state,
isFetching: false,
list: action.list
};
我的组成部分:
class Comments extends Component {
render(){
let ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
let dataSource = ds.cloneWithRows(this.props.list);
return (
<ListView
dataSource={dataSource}
renderRow={this._renderRow.bind(this)}
/>
)
}
_renderRow(rowData: string, sectionID: number, rowID: number) {
return (
<View style={Styles.viewStyle}>
<Comment
name={rowData.user.full_name}
avatar={rowData.user.photo_dir}
comment={rowData.content}
list={rowData.responses}
dispatch={this.props.dispatch}
owner_id={this.props.owner_id}
/>
</View>
)
}
}
你能给我们看看你的减速机吗?我认为你通过这样推动新元素使国家变得沉默:
case 'ADD_ITEM':
return state.push(item)
如果您改变状态,redux将看不到旧状态和新状态之间的差异。相反,您必须返回一个新数组:
case 'ADD_ITEM':
return [...state, item]
编辑
你能分享你的代码吗?特别是更新数据源的部分。如何将其应用于我的代码?我所在的州有一份援助名单。const initialState={list:[],isFetching:false,};我尝试:case types.COMMENTS\u LIST\u UPDATE:return{…state,isFetching:false,LIST:[].concataction.LIST};我认为这不是问题所在,因为我的组件调用了render函数,并使列表与新项处于同一状态,但不绘制新元素列表。是的,它在您的部分看起来不错。你能告诉我更多关于你的渲染部分的信息吗?当然,我在main post上添加了它。你是否尝试先删除数据源检查差异?
case 'ADD_ITEM':
return [].concat(state, [item])