我需要一些帮助来思考。我现在得到并显示我的数据库中的用户列表,具体取决于用户是设置为true还是false。 这工作正常,但是当我在数据库中将用户从true更改为false时,我想更新显示的列表。
如果我重新渲染页面,componetWillMount将为我完成这项工作,但我想更新列表而不重新渲染它。
我已经看过并尝试过使用componentWillUpdate,但无法使其正常工作。
class activeUser extends Component {
// Call fetchList to get access to the users
componentWillMount () {
this.props.fetchList()
this.createDataSource(this.props)
}
componentWillReceiveProps (nextProps) {
// nextProps are the next set of props that this component
// will be rendered with
// this.props is still the old set of props
this.createDataSource(nextProps)
}
createDataSource ({ users }) {
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
})
this.dataSource = ds.cloneWithRows(users)
}
// Render out the users
renderRow (user) {
return <ListUserItem user={user} />
}
render () {
return (
<View>
<View style={{ height: 320, justifyContent: 'center', alignItems:
'center', marginTop: 35 }} >
<ListView
showsVerticalScrollIndicator={false}
enableEmptySections
dataSource={this.dataSource}
renderRow={this.renderRow}
/>
</View>
</View>
)
}
}
const mapStateToProps = state => {
const users = _.map(state.list, (val) => {
return {...val}
})
return { users }
}
export default connect(mapStateToProps, {fetchList})(GoingOut)