react native handle null safety
const adventurer = {
name: 'Alice',
cat: {
name: 'Dinah'
}
};
const dogName = adventurer.dog?.name;
console.log(dogName);
// expected output: undefined
console.log(adventurer.someNonExistentMethod?.());
// expected output: undefined
Example:
const value = undefinedCheck(appConfigurations?.language, 'EN');
console.log(value);
export function undefinedCheck(value, defaultValue) {
return (value !== undefined && value !== '' && value !== null) ? value : defaultValue;
}