Skip to content

Commit

Permalink
fix: dont use window for component scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jul 8, 2020
1 parent 2fb389d commit ffed14c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/components/ReferenceExample.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import PropTypes from 'prop-types';
import styles from './ReferenceExample.module.scss';
import ReferencePreview from './ReferencePreview';
Expand All @@ -16,13 +16,6 @@ const nerdletStateContextMock = {
entityGuid: 'MTIzNDU2fEZPT3xCQVJ8OTg3NjU0MzIx',
};

const SCOPE = {
...window.__NR1_SDK__.default,
navigation: {
getOpenLauncherLocation: () => {},
},
};

const ReferenceExample = ({
className,
example,
Expand All @@ -35,6 +28,16 @@ const ReferenceExample = ({
} = window.__NR1_SDK__.default;
const { live } = example.options;

const scope = useMemo(
() => ({
...window.__NR1_SDK__.default,
navigation: {
getOpenLauncherLocation: () => {},
},
}),
[]
);

const Preview = useCallback(
({ className }) => (
<ReferencePreview
Expand All @@ -56,7 +59,7 @@ const ReferenceExample = ({
language="jsx"
live={live}
preview={live}
scope={SCOPE}
scope={scope}
components={{ Preview }}
>
{example.sourceCode}
Expand Down

0 comments on commit ffed14c

Please sign in to comment.