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

Conversation

mrscobbler
Copy link
Contributor

Would love some feedback on these terms -- let me know if there are other terms that should be added.

@mrscobbler mrscobbler mentioned this pull request Nov 3, 2016
13 tasks
@mrscobbler mrscobbler changed the title initial draft of glossary docs [new docs] initial draft of glossary docs Nov 8, 2016
@gaearon gaearon self-assigned this Nov 8, 2016
@gaearon
Copy link
Collaborator

gaearon commented Nov 17, 2016

Hey, sorry about the long time for review.
I think it would really help to add links to the corresponding docs.

For example, the JSX paragraph can have something like "To get familiar with JSX, read [Intro to JSX]. You can also read [JSX in Depth] to learn more about it."

Same for other topics.

@mrscobbler
Copy link
Contributor Author

Ok! What about the list of terms? Is there anything I should add?

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. 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). Component names should also always start with a capital letter (`<Wrapper/>` **not** `<wrapper/>`)


### `props`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's say just "Props" in the header. Same for "Children" and "State".

@gaearon
Copy link
Collaborator

gaearon commented Nov 17, 2016

Looks good for the first pass. I think it would be great to add "bundler", "compiler", etc—all the terms people might see on other doc pages. Think somebody who never wrote any JavaScript: which words would they be confused about as they read through our docs?

@mrscobbler
Copy link
Contributor Author

Ok! Gives me a good excuse to thoroughly read through the docs! :)

@mrscobbler
Copy link
Contributor Author

So sorry for the delay! I've added more terms and included links to relevant documentation where necessary. Check it out @gaearon when you get a chance.

Copy link
Contributor

@aweary aweary left a comment

Choose a reason for hiding this comment

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

Looking really good, added some feedback!

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.

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.

## 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.

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

## 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 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 👍

## 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)

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.

`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

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.

## [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.

* 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

@gaearon
Copy link
Collaborator

gaearon commented Jan 27, 2017

@aweary Thanks for jumping on this!

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.

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.

@kkemple
Copy link

kkemple commented Mar 20, 2017

@mrscobbler is this still being actively developed?

@mrscobbler
Copy link
Contributor Author

yes, I've made some of the changes but haven't had a chance to push them to github. Is this something you're interested in collaborating on?

@kkemple
Copy link

kkemple commented Mar 20, 2017

yeah! would love to help out! 😄

@mrscobbler
Copy link
Contributor Author

@aweary made the changes you requested! Take a look. @kkemple if you think there's anything else we should add make a pull request! /cc @gaearon

@bvaughn
Copy link
Contributor

bvaughn commented Oct 6, 2017

Thank you for submitting this PR! 😄

Unfortunately the documentation and source code for reactjs.org has been moved to a different repository: https://github.com/reactjs/reactjs.org

I realize this PR is old and there may no longer be interest in seeing it merged. If there is, please open a new PR there. Sorry for the inconvenience!

(For more backstory on why we moved to a new repo, see issue #11075)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants