File tree Expand file tree Collapse file tree 4 files changed +6277
-6137
lines changed Expand file tree Collapse file tree 4 files changed +6277
-6137
lines changed Original file line number Diff line number Diff line change 1
1
class Ctx {
2
- constructor ( ) {
2
+ constructor ( React ) {
3
3
this . _temp = '' ;
4
4
this . _parentTemp = `"use strict";\nreturn @temp;` ;
5
5
this . _com = null ;
6
+ window . React = window . React || React ;
6
7
if ( ! ( Object . prototype . hasOwnProperty . call ( window , 'Babel' ) && typeof window . Babel === 'object' ) ) {
7
8
throw new Error ( `string-to-react-component package needs @babel/standalone for working correctly.
8
9
you should load @babel/standalone in the browser.` ) ;
Original file line number Diff line number Diff line change 1
1
import Ctx from './ctx.js' ;
2
2
import StringToReact from './strintToReact.js' ;
3
- const getCtx = ( ) => new Ctx ( ) ;
3
+ const getCtx = ( options ) => new Ctx ( options ) ;
4
4
export default StringToReact . bind ( null , { getCtx} ) ;
Original file line number Diff line number Diff line change 1
- import React , { useRef } from 'react' ;
1
+ import React , { useRef } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- window . React = window . React || React ;
4
3
function StringToReactComponent ( { getCtx} , props ) {
5
4
const ref = useRef ( null ) ;
6
- if ( ! ref . current ) {
7
- ref . current = getCtx ( ) ;
8
- }
5
+ ref . current = ref . current || getCtx ( React ) ;
9
6
const babelOptions = props . babelOptions || { } ;
10
7
const GeneratedComponent = ref . current . updateTemplate ( props . children , babelOptions ) . getComponent ( ) ;
11
8
const data = props . data || { } ;
You can’t perform that action at this time.
0 commit comments