Overview
ReactJS overview
ReactJS is a JavaScript library for building user interfaces.
Components and props
Components are the basic building block of ReactJS. Conceptually, they are like JavaScript functions. They accept arbitrary inputs props
and return React elements describing what should appear on the screen.
The simplest way to define a component is to write a JavaScript function:
This function is a valid React component because it accepts a single props
(which stands for properties) object argument with data and returns a React element. Such components are called function components
because they are literally JavaScript functions.
Another way to define a component is to use an ES6 class:
The above two components are equivalent from React's point of view.
JSX
React components use JSX, a syntax extension to JavaScript. During the build process, the JSX code is transpiled to regular JavaScript (ES5) code.
The following two examples are equivalent:
Elements
New React elements are created from component classes using the createElement
function:
This function takes three arguments:
type
can be either a tag name string (such asdiv
orspan
), or a component class.props
contains a list of attributes passed to the new element.children
contains the child node(s) of the new element (which are additional React components).
Safe by design
ReactJS implements security controls by design, for example, string variables in views are escaped automatically.
References
Last updated