Syntax error in updated 0.12 reactions?

When I try to start the Migration with ... in the JSX example

var FancyCheckbox = React.createClass({ render: function() { var { checked, ...other } = this.props; var fancyClass = checked ? 'FancyChecked' : 'FancyUnchecked'; // `other` contains { onClick: console.log } but not the checked property return ( <div {...other} className={fancyClass} /> ); } }); React.render( <FancyCheckbox checked={true} onClick={console.log}> Hello world! </FancyCheckbox>, document.body ); 

I get Uncaught SyntaxError: Unexpected token { . Same thing when I try to run it in jsfiddle

Is this a mistake or some kind of additional code conversion necessary for this?

+5
source share
1 answer

To use this feature, you must have consistency . Unfortunately, the script integration you are using is not enabled.

A commit has recently been added that adds it, so most likely it will be there.

If you want to use it right away, you can either place the file somewhere, or simply add the script directly to the script:

 <script> (function () { var tag = document.querySelector( 'script[type="application/javascript;version=1.7"]' ); if (!tag || tag.textContent.indexOf('window.onload=function(){') !== -1) { alert('Bad JSFiddle configuration, please fork the original React JSFiddle'); } tag.setAttribute('type', 'text/jsx;harmony=true'); tag.textContent = tag.textContent.replace(/^\/\/<!\[CDATA\[/, ''); })(); </script> 

The important line is 'text/jsx;harmony=true' . Check the updated script .

+5
source

Source: https://habr.com/ru/post/1206165/


All Articles