Created
August 3, 2021 03:18
-
-
Save milksense/910a8a5f88e96ab00d069dba1f37f413 to your computer and use it in GitHub Desktop.
Проверяет, можно использовать браузерное API в текущем окружении
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Проверяет, можно использовать браузерное API в текущем окружении. | |
* | |
* @example | |
* if (canUseDOM()) { | |
* document.querySelector('...') | |
* } | |
*/ | |
export const canUseDOM = (): boolean => { | |
return ( | |
typeof window !== 'undefined' && | |
typeof window.document !== 'undefined' && | |
typeof window.document.createElement !== 'undefined' | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment