Skip to content

Commit

Permalink
Fix "ReferenceError: document is not defined" issue (GH-44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtyomVancyan authored Jul 21, 2024
2 parents dfa9e86 + ae036c7 commit 96d7c7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.8",
"version": "0.1.9",
"name": "react-phone-hooks",
"description": "React hooks and utility functions for parsing and validating phone numbers.",
"keywords": [
Expand Down
19 changes: 11 additions & 8 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ export const jsonToCss = (stylesheet: object) => {

export const injectStyles = (cssText: string) => {
/** Inject the given `cssText` in the document head */
const style = document.createElement("style");
style.setAttribute("type", "text/css");
try {
const style = document.createElement("style");
style.setAttribute("type", "text/css");

if ((style as any).styleSheet) {
(style as any).styleSheet.cssText = cssText;
} else {
style.appendChild(document.createTextNode(cssText));
}
if ((style as any).styleSheet) {
(style as any).styleSheet.cssText = cssText;
} else {
style.appendChild(document.createTextNode(cssText));
}

document.head.appendChild(style);
document.head.appendChild(style);
} catch (err) {
}
}

0 comments on commit 96d7c7e

Please sign in to comment.