I have table, filling from Web - Api.
When I am deleting department, linked to some user. Department object getting null. And I have crash of my react app with such error: TypeError: Cannot read property 'name' of null
I've tried ternary like that, but it didn't help
(typeof user !=='undefined' && typeof user.department.name !=='undefined') ? user.department.name : ''
refreshList()
{
fetch("https://localhost:5001/api/users")
.then(response=> response.json())
.then(data=> {
this.setState({users:data});
});
}
render(){
const {users, userid, username, userfullname, department} = this.state;
return(
<tbody>
{users.map(user=>
<tr key = {user.id}>
<td>{user.id}</td>
<td>{user.userName}</td>
<td>{user.fullName}</td>
<td>{user.department.name}</td> <---- here i am getting crash when department is null
....
)