Skip to content

Commit 96d7c7e

Browse files
Fix "ReferenceError: document is not defined" issue (GH-44)
2 parents dfa9e86 + ae036c7 commit 96d7c7e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.8",
2+
"version": "0.1.9",
33
"name": "react-phone-hooks",
44
"description": "React hooks and utility functions for parsing and validating phone numbers.",
55
"keywords": [

src/styles.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ export const jsonToCss = (stylesheet: object) => {
1111

1212
export const injectStyles = (cssText: string) => {
1313
/** Inject the given `cssText` in the document head */
14-
const style = document.createElement("style");
15-
style.setAttribute("type", "text/css");
14+
try {
15+
const style = document.createElement("style");
16+
style.setAttribute("type", "text/css");
1617

17-
if ((style as any).styleSheet) {
18-
(style as any).styleSheet.cssText = cssText;
19-
} else {
20-
style.appendChild(document.createTextNode(cssText));
21-
}
18+
if ((style as any).styleSheet) {
19+
(style as any).styleSheet.cssText = cssText;
20+
} else {
21+
style.appendChild(document.createTextNode(cssText));
22+
}
2223

23-
document.head.appendChild(style);
24+
document.head.appendChild(style);
25+
} catch (err) {
26+
}
2427
}

0 commit comments

Comments
 (0)