나는 Redux와의 React-Native 프로젝트를 가지고 있습니다.ListView는 상태 업데이트 후 새 항목을 렌더링하지 않습니다.
구성 요소 "ParentComponent"에 "주석"이 포함되어 있습니다.
덧글 추가 후 내 "의견"구성 요소는 업데이트 된 상태를 수신하고 소품에서 새 배열로 렌더링 기능을 호출합니다. 그러나 listView에 새 셀을 그려서는 안됩니다.
내 ActionComments 코드
addComment :
if(parent_id){
commentsList[parent_index].responses.push(responseObject)
}else{
commentsList.splice(0, 0, responseObject)
}
Actions.pop()
var newList = commentsList
dispatch(commentsListUpdate(newList))
CommentListUpdate :
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>
)
}
}
당신이 코드의 비트를 공유 할 수 없습니다 : 대신, 당신은 새로운 배열을 반환해야? 특히 데이터 소스를 업데이트하는 부분. –