-2
I’m doing a project of the kind CRUD
with the React
and in compiling it appeared:
"Unhandled Rejection (TypeError): this.setState.list is undefined"
export default class UserCrud extends Component {
state = { ...initialState}
clear () {
this.setState({user: initialState.user})
}
save () {
const user = this.state.user
const method = user.id ? 'put' : 'post'
const url = user.id ? `${baseUrl}/${user.id}` : baseUrl //outro erro
axios[method] (url, user)
.then(resp => {
const list = this.getUpdateList(resp.data)
this.setState({user: initialState.user, list})
})
}
getUpdateList (user) { // onde está o erro
const list = this.setState.list.filter(u => u.id !== user.id)
list.unshift(user)
return list
}
updateField (event) {
const user = { ...this.state.user}
user[event.target.name] = event.target.value
this.setState({user})
}
initialState
What is that? There’s no such thing:const list = this.setState.list.filter(u => u.id !== user.id)
and I think pure supposition that isconst list = this.state.list.filter(u => u.id !== user.id)
– novic