Every line of 'react variable in string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
69 render ( str ) { 70 71 if ( !String.isString( str ) ) { 72 return str; 73 } 74 75 var _this = this; 76 return str.replace( /\$?\{([^}]+)\}/g, function ( match, name ) { 77 var val = _this.get( name ) || match; 78 if ( val === undefined ) { 79 throw new Error( 'Error resolving variable ' + match ); 80 return val; 81 } 82 if ( val instanceof Function ) { 83 val = val( global, require, _this ); 84 } 85 else if ( val instanceof Object ) { 86 val = val.toString( _this ); 87 } 88 if ( String.isString( val ) && val != match ) { 89 val = _this.render( val ); 90 } 91 return val; 92 } ); 93 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
14 function injectProps(str, props) { 15 return str.replace(/<svg([^>]+)>/, `<svg$1 {...${props}}>`) 16 }
10 function renderToString(Component, props) { 11 return ReactDOMServer 12 .renderToString(React.createElement(Component, props)) 13 .replace(REACT_ATTR_REGEX, ''); 14 }