InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

React Tutorials

  • Overview
  • Hello world (jsx)
  • jsx to javascript (babel cli)
  • jsx offline transformation
  • Hello world (javascript)
  • click hander (jsx)
  • click handler (javascript)
  • clock example
  • ajax
  • React FAQ
 
  • Home
  • > Tutorials
  • > Javascript
  • > React

React javascript render hello world

on Feb 11, 2016

React render can be written purely in Javascript without jsx. For JSX version of this tutorial you can visit React jsx hello world. Here is javascript version of same tutorial (without jsx).

React javascript render – using React.createElement

Here we are not setting any element properties (null).

<script src="https://fb.me/react-0.14.7.js"></script>
<script src="https://fb.me/react-dom-0.14.7.js"></script>

<div id="hello"></div>

<script type="text/javascript">
ReactDOM.render(React.createElement(
  'h1',
  null,
  'Hello world'
), document.getElementById('hello'));
</script>
refresh done
try it online

React javascript render – set className property

Here we will set className in properties argument.

<script src="https://fb.me/react-0.14.7.js"></script>
<script src="https://fb.me/react-dom-0.14.7.js"></script>

<style type="text/css" media="screen">
.foo {background-color:lightgreen;} 
</style>
<div id="hello"></div>

<script type="text/javascript">
ReactDOM.render(React.createElement(
  'h1',
  {className:"foo"},
  'Hello world'
), document.getElementById('hello'));
</script>
refresh done
try it online

React javascript render – using factory React.DOM.h1

Note that React.DOM.h1 is a built in factory which creates component h1 for us.

<script src="https://fb.me/react-0.14.7.js"></script>
<script src="https://fb.me/react-dom-0.14.7.js"></script>

<div id="hello"></div>

<script type="text/javascript">
ReactDOM.render(React.DOM.h1(
  null,
  'Hello world'
), document.getElementById('hello'));
</script>
refresh done
try it online

Few points to note

  1. If you inspect hello world element in Chrome, here is how the dom element looks like.
    react-javascript-render-hello-world-inspect-dom
  2. Babel javascript compiler is not needed here as there is no jsx.

Suggested posts:

  1. React – JSXTransformer vs babel – which one should be used?
  2. PHP array map example
  3. CSS transform – skew (skewX and skewY)
  4. jquery ajax – post form having file uploads
  5. React basic clock example using setInterval
  6. React.render vs ReactDOM.render – which one should be used?
  7. React jsx hello world with offline transformation
  8. React component tutorial with click handler – javascript version
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Javascript, React, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress