Search code examples
ecmascript-6jsxlet

Can I use 'let' in jsx syntax?


I've tried to create some variables using es6 let in jsx syntax, but firefox gave me an error...

I haven't problems when I using var

Can I use let in jsx syntax and if it's impossible, can you explain me why?


Solution

  • Can I use 'let' in jsx syntax?

    Yes. JSX is merely an extension of the JavaScript syntax, so any valid JavaScript syntax can be used with JSX (small example using the babel repl).

    Of course you have to convert JSX to JavaScript before you can run the code in a JS engine and the engine has to support the features you want to use (such as let).