Skip to content

Commit c56a396

Browse files
check if window is an object
1 parent 5c886ef commit c56a396

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/ctx.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {TransformOptions} from '@babel/core';
22
import type {TBabel, TReact, IStringToReactApi} from './index.d';
3-
import React, {FC, PropsWithChildren} from 'react';
3+
import {FC, PropsWithChildren} from 'react';
44
class Ctx implements IStringToReactApi {
55
_temp: string = '';
66
_parentTemp: string = `"use strict";\nreturn @temp;`;
@@ -9,7 +9,9 @@ class Ctx implements IStringToReactApi {
99
};
1010
_getBabel: () => TBabel;
1111
constructor(React: TReact, Babel: TBabel) {
12-
window.React = window.React || React;
12+
if (typeof window === 'object') {
13+
window.React = window.React || React;
14+
}
1315
if (!Babel) {
1416
throw new Error(
1517
`Package "string-to-react-component" has a missing peer dependency of "@babel/standalone" ( requires "^7.23.10" )`,

src/strintToReact.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useRef} from 'react';
1+
import {useRef} from 'react';
22
import type {StringToReactComponentProps, IStringToReactApi, TBabel, TReact} from './index.d';
33
function StringToReactComponent(
44
deps: {getCtx: (react: TReact, Babel: TBabel) => IStringToReactApi; react: TReact; Babel: TBabel},

0 commit comments

Comments
 (0)