I have this table where I fetch the data using firestore. There were some cases where this data is empty. I have this address where city is empty it would show undefined. How would I just display it as blank instead of the word "undefined"?
componentDidMount() {
firestore
.collection("users")
.get()
.then((snapshot) => {
const users = [];
snapshot.forEach((doc) => {
const data = doc.data();
users.push({
"User ID": doc.id,
Address: data.address + ", " + data.city + ", " + data.provice,
}),
});
});
this.setState({ users: users });
})
.catch((error) => console.log(error));
}
city's value isnull, you can do this:data.city ?? ''. Ifcity's value is a String called 'undefined', then you can use an if statement.String city = data.city; if (city == 'undefined') city = '';