web
web copied to clipboard
`useCheckAPI` hook with checks for APIs availability
useCheckAPI
This hook would check for the availability of various browser APIs.
Motivation
This hook is essential for supporting older browsers and ensuring compatibility across different environments. It would allow developers to gracefully handle scenarios where certain browser APIs are not available.
Implementation
I am willing to implement this feature myself. Please reach out to me on Discord to guide me on how to get started with the project.
Example Usage
import { useCheckAPI } from 'react-hookz';
const MyComponent = () => {
const isServiceWorkerAvailable = useCheckAPI('serviceWorker');
const isLocalStorageAvailable = useCheckAPI('localStorage');
if (!isServiceWorkerAvailable) {
console.log('Service Worker API is not supported in this browser.');
}
return (
<div>
{isLocalStorageAvailable ? 'LocalStorage is available' : 'LocalStorage is not available'}
</div>
);
};
AND/OR
// check all services as an object
const servicesStatuses = useCheckAPI();
// servicesStatuses.localStorage -- true