So I'm having this little generator, the info that get displayed should correspond to what values are populated on the database, the example below is a physical address
this.setState({
   companyEmail: json.data.companyEmail,
   company: json.data.company,
   line1: json.data.line1,
   line2: json.data.line2,
   city: json.data.city,
   ... 
});
So I could initialize those values with null, undefined or "" it does not matter, on the fetch request the typeof those empty values turn to undefined.
Firebase don't like that, for me it cause no issue, I could hide the element by checking if it's true or false like so
{line1 && <span>{line1}<br /></span>}
{line2 && <span>{line2}<br /></span>}
Well I mean it works until I tried updating the database, I got this error
Error: Reference.set failed: First argument contains undefined in property 'master.business.info.line2'
What I want to do is kindof turning undefined to null, because when sending null remove the child from the db, it's treated like a real value.
On the server side, it's regular db update
master.update({
   company: company,
   line1: line1,
   line2: line2,
   city: city,
   ... 
})
.then(() => {
   response.sendStatus(200);
}).catch(function (err) {
   console.log(err);
   response.sendStatus(204);
});
I could use if statement and setState accordingly but that's too much work. I need to make to fetch request because I need those values, it's a form to edit info.
Also using empty strings like "" is not good, it gets display inside span, paragraph or whatever.
This is not a duplicate, on react.js my goal is to not setState for undefined values and keep the init values on the constructor.
 
    