Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JSX without <script type="text/jsx"> tag?

I'm working on a chrome extension, specifically the content script functionality which injects my js into a website.

Since I'm basically just working with a .js fil that gets injected, I am unable to make make this declaration which seems necessary for jsx to work.

  <script type="text/jsx">
  /**@jsx React.DOM*/

Is there any other way I can utilize JSX?

like image 835
Austin Wang Avatar asked Apr 05 '14 00:04

Austin Wang


People also ask

Is it possible to use React without JSX?

JSX is not a requirement for using React. Using React without JSX is especially convenient when you don't want to set up compilation in your build environment. Each JSX element is just syntactic sugar for calling React.

Can we use JSX in HTML?

Coding JSXJSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement() and/or appendChild() methods. JSX converts HTML tags into react elements. You are not required to use JSX, but JSX makes it easier to write React applications.

What is ${} in JSX?

The ${} is template literals.


1 Answers

Since running the JSX transformation is slower than not running it, you probably want to just precompile the JSX (using the jsx binary provided by react-tools) when you distribute the extension. That said, if you include JSXTransformer.js then there's a JSXTransformer.exec(...) method which transforms and evals its argument.

like image 189
Sophie Alpert Avatar answered Sep 30 '22 14:09

Sophie Alpert