Languages
[Edit]
EN

React - runtime compilation in browser with Babel example

7 points
Created by:
chelsea
806

In this short article, we would like to show how to run React JSX script directly in web browser without previous compilation - it is runtime compilation.

The solution for the problem is to:

  1. inside <head> element, add the following scripts:
    or:
  2. inside <body> element:
    • add <div id="root"></div> element,
    • add <script type="text/babel"></script> and paste JSX code inside,
      Hint: do not forget to render application inside div#root element (ReactDOM.render() function).

 

Practical examples

Edit

In this section, you can find development and production versions for the same source code.

Development version:

Edit

Production version:

Edit

 

Alternative titles

  1. React - compile and run in browser (Babel transpiler)
  2. React - compile and run in browser (Babel compiler)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

ReactJS

React - runtime compilation in browser
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join