• Complain

it-ebooks - React Enlightenment

Here you can read online it-ebooks - React Enlightenment full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, publisher: iBooker it-ebooks, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

it-ebooks React Enlightenment
  • Book:
    React Enlightenment
  • Author:
  • Publisher:
    iBooker it-ebooks
  • Genre:
  • Year:
    2017
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

React Enlightenment: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "React Enlightenment" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

it-ebooks: author's other books


Who wrote React Enlightenment? Find out the surname, the name of the author of the book and a list of all author's works by series.

React Enlightenment — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "React Enlightenment" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
3.1 Using react.js & react-dom.js
Using react.js and react-dom.js in an HTML Page

The react.js file is the core file needed to create React elements and write react components. When you intend to render your components in an HTML document (i.e., the DOM) you'll also need the react-dom.js file. The react-dom.js file is dependent on the react.js file and must be included after first including the react.js file.

An example of an HTML document properly including React is shown below.

< html > < head > < script src = "https://fb.me/react-15.2.0.js" > </<span class="xml">script > < script src = "https://fb.me/react-dom-15.2.0.js" > </<span class="xml">script > </<span class="xml">head > < body > </<span class="xml">body > </<span class="xml">html >

With the react.js file and react-dom.js file loaded into an HTML page it is then possible to create React nodes/components and then render them to the DOM. In the HTML below a HelloMessage React component is created containing a React

node that is rendered to the DOM inside of theHTML element. < html > < head > < script src = "https://fb.me/react-15.2.0.js" > </<span class="xml">script > < script src = "https://fb.me/react-dom-15.2.0.js" > </<span class="xml">script > </<span class="xml">head > < body > < div id = "app" > </<span class="xml">div > < script > var HelloMessage = React.createClass({ displayName: 'HelloMessage' , render: function render () { return React.createElement( 'div' , null , 'Hello ' , this .props.name); } }); ReactDOM.render(React.createElement(HelloMessage,{ name: 'John' }), document .getElementById( 'app' )); </<span class="xml">script > </<span class="xml">body > </<span class="xml">html >

This setup is all you need to use React. However this setup does not make use of JSX. The next section will discuss JSX usage.

Notes
  • An alternative react.js file called react-with-addons.js is available containing a collection of utility modules for building React applications. The "addons" file can be used in place of the react.js file.
  • Don't make the element the root node for your React app. Always put a root
    into , give it an ID, and render into it. This gives React its own pool to play in without worrying about what else potentially wants to make changes to the children of the element.
3.2 Using JSX via Babel
Using JSX via Babel

The creation of the React HelloMessage component and React

element node in the HTML page below was done using the React.createClass() and React.createElement() functions. This code should look familiar as it is identical to the HTML from the previous section. This HTML will run without errors in ES5 browsers. < html > < head > < script src = "https://fb.me/react-15.2.0.js" > </<span class="xml">script > < script src = "https://fb.me/react-dom-15.2.0.js" > </<span class="xml">script > </<span class="xml">head > < body > < div id = "app" > </<span class="xml">div > < script > var HelloMessage = React.createClass({ displayName: 'HelloMessage' , render: function render () { return React.createElement( 'div' , null , 'Hello ' , this .props.name); } }); ReactDOM.render(React.createElement(HelloMessage,{ name: 'John' }), document .getElementById( 'app' )); </<span class="xml">script > </<span class="xml">body > </<span class="xml">html >

Optionally, by using JSX via Babel, it is possible to simplify the creation of React elements by abstracting the React.createElement() JavaScript function calls so they can be written in a more natural HTML-like style and syntax.

Instead of writing the following, which uses React.createElement():

return React.createElement( 'div' , null , 'Hello ' , this .props.name);

Using JSX, you can write this:

return < div > Hello {this.props.name} </<span class="xml">div > ;

And then Babel will convert it back to the code which uses React.createElement() so it can be parsed by a JavaScript engine.

Loosely stated you can consider JSX a form of HTML that you can directly write in JavaScript that requires a transformation step, done by Babel, into ECMAScript 5 code that browsers can run.

More will be said about JSX in the JSX chapter. For now, just realize that JSX is an optional abstraction provided for your convenience when creating React elements and it won't run in ES5 browsers without first being transformed by Babel.

Transforming JSX via Babel in the Browser

Normally, Babel is setup to automatically process your JavaScript files during development using the Babel CLI tool (e.g., via something like webpack). However, it is possible to use Babel directly in the browser by way of a script include. As we are just getting started we'll avoid CLI tools or learning a module loader to focus on learning React. Note that you should never use this browser transformation in a production environment.

The Babel project unfortunately, as of Babel 6, no longer provides the script file needed (i.e., browser.js) to transform JSX code to ES5 code in the browser. Thus you will have to use an older version of Babel (i.e., 5.8.23) that provides the needed file (i.e., browser.js) for transforming JSX/ES* in the browser.

Using browser.js (Babel 5.8.23) to Transform JSX in the Browser

In the HTML file below the React code we have been working with to create the HelloMessage component has been updated to use JSX. The transformation of the code is occurring because we have included the browser.js Babel file and given the element a type attribute of type="text/babel".

< html > < head > < script src = "https://fb.me/react-15.2.0.js" > </<span class="xml">script > < script src = "https://fb.me/react-dom-15.2.0.js" > </<span class="xml">script > < script src = "https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js" > </<span class="xml">script > </<span class="xml">head > < body > < div id = "app" > </<span class="xml">div > < script type = "text/babel" > var HelloMessage = React.createClass({ render: function () { return < div > Hello {this.props.name} </<span class="xml">div > ; } }); ReactDOM.render( < HelloMessage name = "John" /> , document.getElementById('app')); </<span class="xml">script > </<span class="xml">body > </<span class="xml">html >

While transforming JSX in the browser is convenient and easy to setup, it isn't ideal because the transformation cost is occurring at runtime. This will slow down your web pages and may cause memory issues. Therefore using browser.js is not a production solution.

You should be aware that the code examples used in this book via JSFiddle will be using the browser.js (Babel 5.8.23) to transform JSX into ES5 code. In other words, JSFiddle is pretty much doing what you see in the HTML file above when running React code.

Notes
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «React Enlightenment»

Look at similar books to React Enlightenment. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «React Enlightenment»

Discussion, reviews of the book React Enlightenment and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.