Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[new docs] initial draft of glossary docs #8199

Closed
wants to merge 8 commits into from
100 changes: 100 additions & 0 deletions docs/docs/reference-glossary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---

id: glossary
title: A Glossary of Terms in React
permalink: docs/glossary.html

---

#A Glossary of Terms in React


## Single Page Application
A single page application is an application that loads a single HTML page and all the necessary assets (CSS, Images & JavaScript) required for the application to run. Any interactions with the page or subsequent pages do not require a round trip to the server which means the page is not reloaded.


## ES6/ES2015
ES6 AKA ES2015 is the current version of the ECMAScript Language Specification standard, which the JavaScript language is an implementation of. It includes many additions to the previous versions such as: arrow functions, classes, template literals, and `let` and `const` statements.

## Compilers/Transpilers
A JavaScript compiler (or transpiler) takes JavaScript code, transforms it and returns JavaScript code in a different format. The most common use case is to take ES2015/ES6 syntax and transform it into syntax that browsers are capable of interpreting. Babel is the compiler used with React.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's too pedantic to matter, but technically only transpilers, a subset of compilers, take source code and return source code. Maybe we can clarify this, something like:

A JavaScript transpiler is a compiler that takes JavaScript code, transforms it, and returns JavaScript code in a different format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yeah -- I'm still a little fuzzy on the difference between transpilers and compilers -- some of the articles I read about it said the words were interchangeable.

Copy link
Contributor

@aweary aweary Jan 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its kind of a tricky topic. A compiler is a general term for any program that takes source code in, and outputs some other representation of that code. Usually, compilers will compile code from a source language (like JavaScript) to a lower level target language (like machine code).

A transpiler is a special kind of compiler that takes in one type of source code and outputs another type of source code. So babel is a transpiler since it takes in JavaScript and outputs JavaScript

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were trying to avoid saying "transpiler" in new docs because it confuses everyone. Let's just always say "compiler" and ignore the "transpiler" term. Even Babel docs don't use it.


## Bundlers
Bundlers put all of your JavaScript code & dependency into one "bundle", usually into one file. Some bundlers commonly used in React applications include: Webpack & Browserify
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just use "and" instead of "&" throughout the doc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, missing period at the end.


## Package Manager
Package managers are tools that allow you to manage dependencies in your project. npm & Yarn are two package managers commonly used in React applications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period at the end.


## CDN
CDN stands for Content Delivery Network. CDNs deliver cached, static content from a network of servers across the globe.

## JSX
JSX is a syntax extension to JavaScript. It is similar to a template language. When JSX gets compiled, the result is JavaScript objects called "elements". To get a basic introduction to JSX [see the docs here](https://facebook.github.io/react/docs/introducing-jsx.html) and find a more in-depth tutorial on JSX [here](https://facebook.github.io/react/docs/jsx-in-depth.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When JSX gets compiled, the result is JavaScript objects called "elements".

JSX doesn't get compiled directly to objects. It is typically compiled to function calls that return those objects. In React its compiled to React.createElement calls.

Copy link
Contributor Author

@mrscobbler mrscobbler Jan 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the "intro to JSX" documentation be modified? In this section: https://facebook.github.io/react/docs/introducing-jsx.html#jsx-is-an-expression-too it says "After compilation, JSX expressions become regular JavaScript objects."

For the glossary, I can change the phrasing to say something like "JSX gets compiled to React.createElement() calls which return plain JavaScript objects called 'React elements'." <-- Does that feel like a better description? I was trying to keep the definitions simple and refer people to the actual documentation if they wanted to dig a little deeper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we should probably update that section as its misleading. You can see here that JSX gets compiled to React.createElement calls that return objects called "elements".

Does that feel like a better description?

That definitely sounds better 👍


React DOM uses camelCase property naming convention instead of HTML attribute names.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be helpful to clarify that we use the JavaScript API naming conventions specifically.

For example, class becomes className in JSX, and tabindex becomes tabIndex.

## [Elements](https://facebook.github.io/react/docs/rendering-elements.html)
React elements are the building blocks of React applications. One might confuse elements with a more widely known concept of "components". Elements are what components are "made of".An element describes what you want to see on the screen. React elements are immutable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after third sentence.


```js
const element = <h1>Hello, world</h1>;
```

## [Components](https://facebook.github.io/react/docs/components-and-props.html)
React components are small, resuable pieces of code that return a React element to be rendered to the page. The simplest version of React component is a plain JavaScript function that returns a React element:

```js
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
```

Components can also be ES6 classes:

```js
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
```

Components can be broken down into distinct pieces of functionality and used within other components. Components must return a single root element (wrapped in a `div` or other similar container). A good rule of thumb is that if a part of your UI is used several times (Button, Panel, Avatar), or is complex enough on its own (App, FeedStory, Comment), it is a good candidate to be a reusable component. Component names should also always start with a capital letter (`<Wrapper/>` **not** `<wrapper/>`).


### [`props`](https://facebook.github.io/react/docs/components-and-props.html)
`props` are inputs to a React component. They are data passed down from a parent component to a child component. `props` are readonly -- they should not be modified in any way. All React components must act like pure functions with respect to their `props`.

### `this.props.children`
`this.props.children` is available on every component. It contains the content between the opening and closing tags of a component. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For function components, it would just be props.children, since you access it on the passed parameter and not this


```js
<Welcome>Hello world!</Welcome>
```
The string `Hello world!` is available in `this.props.children` in the `Welcome` component.

### [`state`](https://facebook.github.io/react/docs/state-and-lifecycle.html#adding-local-state-to-a-class)
A component's `state` is a snapshot of the data contained in a component. `props` and `state` are different: `state` is user-defined, `props` are received from a parent component.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A component's state is a snapshot of the data contained in a component.

I'm worried this might sound misleading; someone might think state is a periodical snapshot of the props passed in or something. Maybe rephrase to something like:

State is a way for components to manage data that is private and fully controlled by that component.

That's also closer to what we say in the linked docs page.

state is user-defined, props are received from a parent component.

props are technically user-defined too, just defined in another component 😄 It may be more accurate to say:

state is owned and controlled by the component that created it. props are received from a parent component.


## [Lifecycle Methods](https://facebook.github.io/react/docs/state-and-lifecycle.html#adding-lifecycle-methods-to-a-class)
Lifecycle methods are custom functionality that gets executed during the different phases of a component. There are methods available when the component gets created and inserted into the DOM ([mounting](https://facebook.github.io/react/docs/react-component.html#mounting)), when the component updates and when the component gets unmounted or removed from the DOM.

## [Controlled](https://facebook.github.io/react/docs/forms.html#controlled-components) vs. [Uncontrolled Components](https://facebook.github.io/react/docs/uncontrolled-components.html)
React has two different approaches to dealing with form inputs. An input form element whose value is controlled by React is called a *controlled component*. An *uncontrolled component* is an input that is just like any normal input we would use outside of React. When a user inputs data into a form field (an input box, dropdown, etc) the updated information is reflected.

## [Keys](https://facebook.github.io/react/docs/lists-and-keys.html)
A "key" is a special string attribute you need to include when creating lists of elements. Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside an array to give the elements a stable identity.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A "key" is a special string attribute you need to include when creating lists of elements.

I don't think there's any specific restriction that says a key has to be a string. It's the most common thing to use, but you could also use numbers, or even objects.


## [Refs](https://facebook.github.io/react/docs/refs-and-the-dom.html)
React supports a special attribute that you can attach to any component. When the ref attribute is used on an HTML element, the ref callback receives the underlying DOM element as its argument. This allows you to have direct access to the DOM element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refs can be functions or strings (string refs are pretty-much-legacy but still allowed). Also, missing a period at the end.


## [Events](https://facebook.github.io/react/docs/handling-events.html)
Handling events with React elements has some syntactic differences:

* React events are named using camelCase, rather than lowercase.
* With JSX you pass a function as the event handler, rather than a string.


## Reconciliation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's link to the reconcilliation doc page here: https://facebook.github.io/react/docs/reconciliation.html

When a component's props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with the previously rendered one. When they are not equal, React will update the DOM. This process is called `reconciliation`