I have an async function that checks the permission status in a device. This is the function:
notificationsAllowed = async () => {
const allowed = await requestNotifications(['alert', 'sound']).then((res) => {
if (res.status == "granted") {
return true;
}
return false;
});
return allowed;
}
allowed
is boolean
, but when I try to use this function (for example, to set a switch to true or false) I get an object for some reason.
This is how I try to use it:
const allowed = NotificationsManager.getInstance().notificationsAllowed().then((res) => {
return res;
});
const [isEnabled, setIsEnabled] = useState(allowed);
It seems like allowed is of type Promise<boolean>
but I can't use async await because it is inside a functional component.