Reputation: 46479
Following syntax
const INITIAL_STATE = {
userIsActive: getAccount() ? getAccount().status === "open" : false
};
Causes browser to throw TypeError: Object(...) is not a function
error, I pinpointed it to being syntax specific, getAccount() just returns object like
{
status: "open"
}
Changing to this works perfectly fine, even returns correct data
const accStatus = () => {
try {
return getAccount() ? getAccount().status === "open" : false;
} catch (e) {
console.error(e);
return false;
}
};
const INITIAL_STATE = {
userIsActive: accStatus
};
but I don't understand why it doesn't work in the first place?
EDIT: That catch statement is not triggered, which is odd
Upvotes: 0
Views: 2548
Reputation: 15096
In the first example, userIsActive
is a boolean value, whereas in the second example it is a function that returns the boolean. This will probably work:
const INITIAL_STATE = {
userIsActive: () => getAccount() ? getAccount().status === "open" : false
};
Upvotes: 2