I want to write clean-code. I have this react-code (typescript 3.6.4):
<Button color="primary"
size="large"
disabled={props.user.objectArray.find((element)=> {
return element.primaryKey === state.findPrimaryKey
}).isClosed}
onClick={doSomething}>
Download information
Now I get the message, that the return value could be "undefined". Understandable, maybe the primaryKey could not be found in the object array.
I could write a function which checks first for null, but could this be fixed anyhow without a function?
function getBooleanValue() {
let booleanCheck = false;
const temp = props.user.objectArray.find((element) => {
return element.primaryKey === state.findPrimaryKey
});
if (typeof temp !== "undefined") {
booleanCheck = temp.siteClosed;
}
return booleanCheck;
}
How can I write a clean code to get my boolean value?