@@ -10,20 +10,21 @@ import { usePrismTheme } from '~utils/theme'
1010import * as styles from './styles'
1111import * as Icons from '../Icons'
1212
13+ const transformCode = code => {
14+ if ( code . startsWith ( '()' ) || code . startsWith ( 'class' ) ) return code
15+ return `<React.Fragment>${ code } </React.Fragment>`
16+ }
17+
1318export const Playground = ( { code, scope, language } ) => {
1419 const {
1520 themeConfig : { showPlaygroundEditor, showLiveError, showLivePreview } ,
1621 } = useConfig ( )
17-
22+ // Makes sure scope is only given on mount to avoid infinite re-render on hot reloads
23+ const [ scopeOnMount ] = useState ( scope )
1824 const theme = usePrismTheme ( )
1925 const [ showingCode , setShowingCode ] = useState ( ( ) => showPlaygroundEditor )
2026 const [ width , setWidth ] = useState ( ( ) => '100%' )
2127
22- const transformCode = code => {
23- if ( code . startsWith ( '()' ) || code . startsWith ( 'class' ) ) return code
24- return `<React.Fragment>${ code } </React.Fragment>`
25- }
26-
2728 const copyCode = ( ) => copy ( code )
2829
2930 const toggleCode = ( ) => setShowingCode ( s => ! s )
@@ -58,7 +59,7 @@ export const Playground = ({ code, scope, language }) => {
5859 < Resizable { ...resizableProps } data-testid = "playground" >
5960 < LiveProvider
6061 code = { code }
61- scope = { scope }
62+ scope = { scopeOnMount }
6263 transformCode = { transformCode }
6364 language = { language }
6465 theme = { theme }
0 commit comments