Browse Source

Merge branch 'master' of https://github.com/reactjs/reactjs.org into vishalvrv9-docs-inputfile-improvement

main
Vishal Raj 7 years ago
parent
commit
093e1128c7
  1. 4
      .github/PULL_REQUEST_TEMPLATE.md
  2. 8
      .prettierrc.examples
  3. 8
      CONTRIBUTING.md
  4. 6
      content/authors.yml
  5. 2
      content/blog/2017-09-26-react-v16.0.md
  6. 327
      content/blog/2017-11-28-react-v16.2.0-fragment-support.md
  7. 40
      content/blog/2017-12-07-introducing-the-react-rfc-process.md
  8. 389
      content/blog/2017-12-15-improving-the-repository-infrastructure.md
  9. 10
      content/community/conferences.md
  10. 4
      content/community/courses.md
  11. 2
      content/community/examples.md
  12. 3
      content/community/meetups.md
  13. 3
      content/community/tools-comp-workbenches.md
  14. 18
      content/community/tools-starter-kits.md
  15. 5
      content/community/tools-ui-components.md
  16. 66
      content/docs/accessibility.md
  17. 6
      content/docs/addons-create-fragment.md
  18. 2
      content/docs/components-and-props.md
  19. 2
      content/docs/composition-vs-inheritance.md
  20. 77
      content/docs/faq-functions.md
  21. 8
      content/docs/faq-state.md
  22. 67
      content/docs/faq-structure.md
  23. 4
      content/docs/faq-styling.md
  24. 2
      content/docs/forms.md
  25. 142
      content/docs/fragments.md
  26. 12
      content/docs/how-to-contribute.md
  27. 2
      content/docs/implementation-notes.md
  28. 12
      content/docs/introducing-jsx.md
  29. 4
      content/docs/lists-and-keys.md
  30. 2
      content/docs/nav.yml
  31. 9
      content/docs/optimizing-performance.md
  32. 46
      content/docs/reference-dom-elements.md
  33. 2
      content/docs/reference-glossary.md
  34. 2
      content/docs/reference-react-component.md
  35. 6
      content/docs/reference-react-dom.md
  36. 33
      content/docs/reference-react.md
  37. 139
      content/docs/static-type-checking.md
  38. 1
      content/docs/web-components.md
  39. BIN
      content/images/blog/release-script-build-confirmation.png
  40. BIN
      content/images/blog/release-script-build-overview.png
  41. BIN
      content/images/blog/release-script-publish-confirmation.png
  42. 2
      content/tutorial/tutorial.md
  43. 2
      examples/components-and-props/composing-components.js
  44. 21
      examples/components-and-props/extracting-components-continued.js
  45. 21
      examples/components-and-props/extracting-components.js
  46. 2
      examples/components-and-props/rendering-a-component.js
  47. 6
      examples/es5-syntax-example.js
  48. 8
      examples/introducing-jsx.js
  49. 2
      examples/jsx-simple-example.js
  50. 108
      examples/reconciliation/index-used-as-key.js
  51. 108
      examples/reconciliation/no-index-used-as-key.js
  52. 6
      examples/tutorial-expanded-version.js
  53. 14
      flow-typed/glamor.js
  54. 11
      flow-typed/polyfills.js
  55. 3
      flow-typed/slugify.js
  56. 7
      gatsby/onCreateNode.js
  57. 10
      package.json
  58. 2
      src/components/ButtonLink/ButtonLink.js
  59. 2
      src/components/ButtonLink/index.js
  60. 2
      src/components/CodeEditor/CodeEditor.js
  61. 2
      src/components/CodeEditor/index.js
  62. 2
      src/components/Container/Container.js
  63. 2
      src/components/Container/index.js
  64. 2
      src/components/ErrorDecoder/ErrorDecoder.js
  65. 2
      src/components/ErrorDecoder/index.js
  66. 19
      src/components/Flex/Flex.js
  67. 2
      src/components/Flex/index.js
  68. 2
      src/components/Header/Header.js
  69. 2
      src/components/Header/index.js
  70. 14
      src/components/LayoutFooter/ExternalFooterLink.js
  71. 70
      src/components/LayoutFooter/Footer.js
  72. 13
      src/components/LayoutFooter/FooterLink.js
  73. 13
      src/components/LayoutFooter/FooterNav.js
  74. 2
      src/components/LayoutFooter/index.js
  75. 7
      src/components/LayoutHeader/DocSearch.js
  76. 5
      src/components/LayoutHeader/Header.js
  77. 11
      src/components/LayoutHeader/HeaderLink.js
  78. 2
      src/components/LayoutHeader/SearchSvg.js
  79. 2
      src/components/LayoutHeader/index.js
  80. 2
      src/components/MarkdownHeader/MarkdownHeader.js
  81. 2
      src/components/MarkdownHeader/index.js
  82. 2
      src/components/MarkdownPage/MarkdownPage.js
  83. 2
      src/components/MarkdownPage/index.js
  84. 33
      src/components/StickyResponsiveSidebar/StickyResponsiveSidebar.js
  85. 2
      src/components/StickyResponsiveSidebar/index.js
  86. 2
      src/components/TitleAndMetaTags/TitleAndMetaTags.js
  87. 2
      src/components/TitleAndMetaTags/index.js
  88. 2
      src/html.js
  89. 9
      src/icons/logo-white.svg
  90. 10
      src/icons/logo.svg
  91. 10
      src/layouts/index.js
  92. 2
      src/pages/404.js
  93. 2
      src/pages/acknowledgements.html.js
  94. 28
      src/pages/blog/all.html.js
  95. 10
      src/pages/docs/error-decoder.html.js
  96. 147
      src/pages/index.js
  97. 2
      src/pages/jsx-compiler.html.js
  98. 2
      src/prism-styles.js
  99. 4
      src/site-constants.js
  100. 2
      src/templates/blog.js

4
.github/PULL_REQUEST_TEMPLATE.md

@ -3,3 +3,7 @@ Thank you for the PR! Contributors like you keep React awesome!
Please see the Contribution Guide for guidelines:
https://github.com/reactjs/reactjs.org/blob/master/CONTRIBUTING.md
If your PR references an existing issue, please add the issue number below:
#<Issue>

8
.prettierrc.examples

@ -0,0 +1,8 @@
{
"bracketSpacing": false,
"jsxBracketSameLine": true,
"parser": "flow",
"printWidth": 40,
"singleQuote": true,
"trailingComma": "es5"
}

8
CONTRIBUTING.md

@ -34,21 +34,21 @@ When writing step-by-step instructions (e.g. how to install something), try to f
### Syntax
**Prefer JSX to `createElement`.**
#### Prefer JSX to `createElement`.
Ignore this if you're specifically describing `createElement`.
**Use `const` where possible, otherwise `let`. Don't use `var`.**
#### Use `const` where possible, otherwise `let`. Don't use `var`.
Ignore this if you're specifically writing about ES5.
**Don't use ES6 features when equivalent ES5 features have no downsides.**
#### Don't use ES6 features when equivalent ES5 features have no downsides.
Remember that ES6 is still new to a lot of people. While we use it in many places (`const` / `let`, classes, arrow functions), if the equivalent ES5 code is just as straightforward and readable, consider using it.
In particular, you should prefer named `function` declarations over `const myFunction = () => ...` arrows for top-level functions. However, you *should* use arrow functions where they provide a tangible improvement (such as preserving `this` context inside a component). Consider both sides of the tradeoff when deciding whether to use a new feature.
**Don't use features that aren't standardized yet.**
#### Don't use features that aren't standardized yet.
For example, **don't** write this:

6
content/authors.yml

@ -7,9 +7,15 @@ acdlite:
benigeri:
name: Paul Benigeri
url: https://github.com/benigeri
bvaughn:
name: Brian Vaughn
url: https://github.com/bvaughn
chenglou:
name: Cheng Lou
url: https://twitter.com/_chenglou
clemmy:
name: Clement Hoang
url: https://twitter.com/c8hoang
Daniel15:
name: Daniel Lo Nigro
url: http://dan.cx/

2
content/blog/2017-09-26-react-v16.0.md

@ -21,7 +21,7 @@ render() {
}
```
In the future, we'll likely add a special fragment syntax to JSX that doesn't require keys.
[Starting with React 16.2.0](/blog/2017/11/28/react-v16.2.0-fragment-support.html), we are adding support for a special fragment syntax to JSX that doesn't require keys.
We've added support for returning strings, too:

327
content/blog/2017-11-28-react-v16.2.0-fragment-support.md

@ -0,0 +1,327 @@
---
title: "React v16.2.0: Improved Support for Fragments"
author: [clemmy]
---
React 16.2 is now available! The biggest addition is improved support for returning multiple children from a component's render method. We call this feature *fragments*:
Fragments look like empty JSX tags. They let you group a list of children without adding extra nodes to the DOM:
```js
render() {
return (
<>
<ChildA />
<ChildB />
<ChildC />
</>
);
}
```
This exciting new feature is made possible by additions to both React and JSX.
## What Are Fragments?
A common pattern is for a component to return a list of children. Take this example HTML:
```html
Some text.
<h2>A heading</h2>
More text.
<h2>Another heading</h2>
Even more text.
```
Prior to version 16, the only way to achieve this in React was by wrapping the children in an extra element, usually a `div` or `span`:
```js
render() {
return (
// Extraneous div element :(
<div>
Some text.
<h2>A heading</h2>
More text.
<h2>Another heading</h2>
Even more text.
</div>
);
}
```
To address this limitation, React 16.0 added support for [returning an array of elements from a component's `render` method](https://reactjs.org/blog/2017/09/26/react-v16.0.html#new-render-return-types-fragments-and-strings). Instead of wrapping the children in a DOM element, you can put them into an array:
```jsx
render() {
return [
"Some text.",
<h2 key="heading-1">A heading</h2>,
"More text.",
<h2 key="heading-2">Another heading</h2>,
"Even more text."
];
}
```
However, this has some confusing differences from normal JSX:
- Children in an array must be separated by commas.
- Children in an array must have a key to prevent React's [key warning](https://reactjs.org/docs/lists-and-keys.html#keys).
- Strings must be wrapped in quotes.
To provide a more consistent authoring experience for fragments, React now provides a first-class `Fragment` component that can be used in place of arrays.
```jsx{3,9}
render() {
return (
<Fragment>
Some text.
<h2>A heading</h2>
More text.
<h2>Another heading</h2>
Even more text.
</Fragment>
);
}
```
You can use `<Fragment />` the same way you'd use any other element, without changing the way you write JSX. No commas, no keys, no quotes.
The Fragment component is available on the main React object:
```js
const Fragment = React.Fragment;
<Fragment>
<ChildA />
<ChildB />
<ChildC />
</Fragment>
// This also works
<React.Fragment>
<ChildA />
<ChildB />
<ChildC />
</React.Fragment>
```
## JSX Fragment Syntax
Fragments are a common pattern in our codebases at Facebook. We anticipate they'll be widely adopted by other teams, too. To make the authoring experience as convenient as possible, we're adding syntactical support for fragments to JSX:
```jsx{3,9}
render() {
return (
<>
Some text.
<h2>A heading</h2>
More text.
<h2>Another heading</h2>
Even more text.
</>
);
}
```
In React, this desugars to a `<React.Fragment/>` element, as in the example from the previous section. (Non-React frameworks that use JSX may compile to something different.)
Fragment syntax in JSX was inspired by prior art such as the `XMLList() <></>` constructor in [E4X](https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/E4X_for_templating). Using a pair of empty tags is meant to represent the idea it won't add an actual element to the DOM.
### Keyed Fragments
Note that the `<></>` syntax does not accept attributes, including keys.
If you need a keyed fragment, you can use `<Fragment />` directly. A use case for this is mapping a collection to an array of fragments -- for example, to create a description list:
```jsx
function Glossary(props) {
return (
<dl>
{props.items.map(item => (
// Without the `key`, React will fire a key warning
<Fragment key={item.id}>
<dt>{item.term}</dt>
<dd>{item.description}</dd>
</Fragment>
))}
</dl>
);
}
```
`key` is the only attribute that can be passed to `Fragment`. In the future, we may add support for additional attributes, such as event handlers.
### Live Demo
You can experiment with JSX fragment syntax with this [CodePen](https://codepen.io/reactjs/pen/VrEbjE?editors=1000).
## Support for Fragment Syntax
Support for fragment syntax in JSX will vary depending on the tools you use to build your app. Please be patient as the JSX community works to adopt the new syntax. We've been working closely with maintainers of the most popular projects:
### Create React App
Experimental support for fragment syntax will be added to Create React App within the next few days. A stable release may take a bit longer as we await adoption by upstream projects.
### Babel
Support for JSX fragments is available in [Babel v7.0.0-beta.31](https://github.com/babel/babel/releases/tag/v7.0.0-beta.31) and above! If you are already on Babel 7, simply update to the latest Babel and plugin transform:
```bash
# for yarn users
yarn upgrade @babel/core @babel/plugin-transform-react-jsx
# for npm users
npm update @babel/core @babel/plugin-transform-react-jsx
```
Or if you are using the [react preset](https://www.npmjs.com/package/@babel/preset-react):
```bash
# for yarn users
yarn upgrade @babel/core @babel/preset-react
# for npm users
npm update @babel/core @babel/preset-react
```
Note that Babel 7 is technically still in beta, but a [stable release is coming soon](https://babeljs.io/blog/2017/09/12/planning-for-7.0).
Unfortunately, support for Babel 6.x is not available, and there are currently no plans to backport.
#### Babel with Webpack (babel-loader)
If you are using Babel with [Webpack](https://webpack.js.org/), no additional steps are needed because [babel-loader](https://github.com/babel/babel-loader) will use your peer-installed version of Babel.
#### Babel with Other Frameworks
If you use JSX with a non-React framework like Inferno or Preact, there is a [pragma option available in babel-plugin-transform-react-jsx](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx#pragmafrag) that configures the Babel compiler to de-sugar the `<></>` syntax to a custom identifier.
### TypeScript
TypeScript has full support for fragment syntax! Please upgrade to [version 2.6.2](https://github.com/Microsoft/TypeScript/releases/tag/v2.6.2). (Note that this is important even if you are already on version 2.6.1, since support was added as patch release in 2.6.2.)
Upgrade to the latest TypeScript with the command:
```bash
# for yarn users
yarn upgrade typescript
# for npm users
npm update typescript
```
### Flow
[Flow](https://flow.org/) support for JSX fragments is available starting in [version 0.59](https://github.com/facebook/flow/releases/tag/v0.59.0)! Simply run
```bash
# for yarn users
yarn upgrade flow-bin
# for npm users
npm update flow-bin
```
to update Flow to the latest version.
### Prettier
[Prettier](https://github.com/prettier/prettier) will have support for fragments in their upcoming [1.9 release](https://github.com/prettier/prettier/pull/3237).
### ESLint
JSX Fragments are supported by [ESLint](https://eslint.org/) 3.x when it is used together with [babel-eslint](https://github.com/babel/babel-eslint):
```bash
# for yarn users
yarn add eslint@3.x babel-eslint@7
# for npm users
npm install eslint@3.x babel-eslint@7
```
or if you already have it, then upgrade:
```bash
# for yarn users
yarn upgrade eslint@3.x babel-eslint@7
# for npm users
npm update eslint@3.x babel-eslint@7
```
Ensure you have the following line inside your `.eslintrc`:
```json
"parser": "babel-eslint"
```
That's it!
Note that `babel-eslint` is not officially supported by ESLint. We'll be looking into adding support for fragments to ESLint 4.x itself in the coming weeks (see [issue #9662](https://github.com/eslint/eslint/issues/9662)).
### Editor Support
It may take a while for fragment syntax to be supported in your text editor. Please be patient as the community works to adopt the latest changes. In the meantime, you may see errors or inconsistent highlighting if your editor does not yet support fragment syntax. Generally, these errors can be safely ignored.
#### TypeScript Editor Support
If you're a TypeScript user -- great news! Editor support for JSX fragments is already available in [Visual Studio 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48593), [Visual Studio 2017](https://www.microsoft.com/en-us/download/details.aspx?id=55258), and [Sublime Text via Package Control](https://packagecontrol.io/packages/TypeScript). Visual Studio Code will be updated soon, but [can be configured to use TypeScript 2.6.2 and later](https://code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions).
### Other Tools
For other tools, please check with the corresponding documentation to check if there is support available. However, if you're blocked by your tooling, you can always start with using the `<Fragment>` component and perform a codemod later to replace it with the shorthand syntax when the appropriate support is available.
## Installation
React v16.2.0 is available on the npm registry.
To install React 16 with Yarn, run:
```bash
yarn add react@^16.2.0 react-dom@^16.2.0
```
To install React 16 with npm, run:
```bash
npm install --save react@^16.2.0 react-dom@^16.2.0
```
We also provide UMD builds of React via a CDN:
```html
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
```
Refer to the documentation for [detailed installation instructions](/docs/installation.html).
## Changelog
### React
* Add `Fragment` as named export to React. ([@clemmy](https://github.com/clemmy) in [#10783](https://github.com/facebook/react/pull/10783))
* Support experimental Call/Return types in `React.Children` utilities. ([@MatteoVH](https://github.com/MatteoVH) in [#11422](https://github.com/facebook/react/pull/11422))
### React DOM
* Fix radio buttons not getting checked when using multiple lists of radios. ([@landvibe](https://github.com/landvibe) in [#11227](https://github.com/facebook/react/pull/11227))
* Fix radio buttons not receiving the `onChange` event in some cases. ([@jquense](https://github.com/jquense) in [#11028](https://github.com/facebook/react/pull/11028))
### React Test Renderer
* Fix `setState()` callback firing too early when called from `componentWillMount`. ([@accordeiro](https://github.com/accordeiro) in [#11507](https://github.com/facebook/react/pull/11507))
### React Reconciler
* Expose `react-reconciler/reflection` with utilities useful to custom renderers. ([@rivenhk](https://github.com/rivenhk) in [#11683](https://github.com/facebook/react/pull/11683))
### Internal Changes
* Many tests were rewritten against the public API. Big thanks to [everyone who contributed](https://github.com/facebook/react/issues/11299)!
## Acknowledgments
This release was made possible by our open source contributors. A big thanks to everyone who filed issues, contributed to syntax discussions, reviewed pull requests, added support for JSX fragments in third party libraries, and more!
Special thanks to the [TypeScript](https://www.typescriptlang.org/) and [Flow](https://flow.org/) teams, as well as the [Babel](https://babeljs.io/) maintainers, who helped make tooling support for the new syntax go seamlessly.
Thanks to [Gajus Kuizinas](https://github.com/gajus/) and other contributors who prototyped the `Fragment` component in open source.

40
content/blog/2017-12-07-introducing-the-react-rfc-process.md

@ -0,0 +1,40 @@
---
title: "Introducing the React RFC Process"
author: [acdlite]
---
We're adopting an RFC ("request for comments") process for contributing ideas to React.
Inspired by [Yarn](https://github.com/yarnpkg/rfcs), [Ember](https://github.com/emberjs/rfcs), and [Rust](https://github.com/rust-lang/rfcs), the goal is to allow React core team members and community members to collaborate on the design of new features. It's also intended to provide a clear path for ideas to enter the project:
- Create an RFC document detailing your proposal.
- Submit a PR to the [RFC repository](https://github.com/reactjs/rfcs).
- Incorporate feedback into the proposal.
- After discussion, the core team may or may not accept the RFC.
- If the RFC is accepted, the PR is merged.
RFCs are accepted when they are approved for implementation in React. A more thorough description of the process is available in the repository's [README](https://github.com/reactjs/rfcs/blob/master/README.md). The exact details may be refined in the future.
## Who Can Submit RFCs?
Anyone! No knowledge of React's internals is required, nor are you expected to implement the proposal yourself.
As with our other repositories, we do ask that you complete a [Contributor License Agreement](https://github.com/reactjs/rfcs#contributor-license-agreement-cla) before we can accept your PR.
## What Types of Changes Should Be Submitted As RFCs?
Generally, any idea that would benefit from additional review or design before being implemented is a good candidate for an RFC. As a rule of thumb, this means any proposal that adds, changes, or removes a React API.
Not every change must go through the RFC process. Bug fixes or performance improvements that don't touch the API can be submitted directly to the main library.
We now have several repositories where you can submit contributions to React:
- **Issues, bugfixes, and code changes to the main library**: [facebook/react](https://github.com/facebook/react)
- **Website and documentation**: [reactjs/reactjs.org](https://github.com/reactjs/reactjs.org)
- **Ideas for changes that need additional review before being implemented**: [reactjs/rfcs](https://github.com/reactjs/rfcs)
## RFC for A New Context API
Coinciding with the launch of our RFC process, we've submitted a [proposal for a new version of context](https://github.com/reactjs/rfcs/pull/2). The proposal has already received many valuable comments from the community that we will incorporate into the design of the new API.
The context PR is a good example of how a typical RFC should be structured. We're excited to start receiving your proposals!

389
content/blog/2017-12-15-improving-the-repository-infrastructure.md

@ -0,0 +1,389 @@
---
title: "Behind the Scenes: Improving the Repository Infrastructure"
author: [gaearon, bvaughn]
---
As we worked on [React 16](/blog/2017/09/26/react-v16.0.html), we revamped the folder structure and much of the build tooling in the React repository. Among other things, we introduced projects such as [Rollup](https://rollupjs.org/), [Prettier](https://prettier.io/), and [Google Closure Compiler](https://developers.google.com/closure/compiler/) into our workflow. People often ask us questions about how we use those tools. In this post, we would like to share some of the changes that we've made to our build and test infrastructure in 2017, and what motivated them.
While these changes helped us make React better, they don't affect most React users directly. However, we hope that blogging about them might help other library authors solve similar problems. Our contributors might also find these notes helpful!
## Formatting Code with Prettier
React was one of the first large repositories to [fully embrace](https://github.com/facebook/react/pull/9101) opinionated automatic code formatting with [Prettier](https://prettier.io/). Our current Prettier setup consists of:
* A local [`yarn prettier`](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/package.json#L115) script that [uses the Prettier Node API](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/prettier/index.js#L71-L77) to format files in place. We typically run it before committing changes. It is fast because it only checks the [files changed since diverging from remote master](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/shared/listChangedFiles.js#L29-L33).
* A script that [runs Prettier](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/prettier/index.js#L79-L90) as part of our [continuous integration checks](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/circleci/test_entry_point.sh#L10). It won't attempt to overwrite the files, but instead will fail the build if any file differs from the Prettier output for that file. This ensures that we can't merge a pull request unless it has been fully formatted.
Some team members have also set up the [editor integrations](https://prettier.io/docs/en/editors.html). Our experience with Prettier has been fantastic, and we recommend it to any team that writes JavaScript.
## Restructuring the Monorepo
Ever since React was split into packages, it has been a [monorepo](https://danluu.com/monorepo/): a set of packages under the umbrella of a single repository. This made it easier to coordinate changes and share the tooling, but our folder structure was deeply nested and difficult to understand. It was not clear which files belonged to which package. After releasing React 16, we've decided to completely reorganize the repository structure. Here is how we did it.
### Migrating to Yarn Workspaces
The Yarn package manager [introduced a feature called Workspaces](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/) a few months ago. This feature lets you tell Yarn where your monorepo's packages are located in the source tree. Every time you run `yarn`, in addition to installing your dependencies it also sets up the symlinks that point from your project's `node_modules` to the source folders of your packages.
Thanks to Workspaces, absolute imports between our own packages (such as importing `react` from `react-dom`) "just work" with any tools that support the Node resolution mechanism. The only problem we encountered was Jest not running the transforms inside the linked packages, but we [found a fix](https://github.com/facebook/jest/pull/4761), and it was merged into Jest.
To enable Yarn Workspaces, we added `"workspaces": ["packages/*"]` to our [`package.json`](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/package.json#L4-L6), and moved all the code into [top-level `packages/*` folders](https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages), each with its own `package.json` file.
Each package is structured in a similar way. For every public API entry point such as `react-dom` or `react-dom/server`, there is a [file](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/index.js) in the package root folder that re-exports the implementation from the [`/src/`](https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/src) subfolder. The decision to point entry points to the source rather than to the built versions was intentional. Typically, we re-run a subset of tests after every change during development. Having to build the project to run a test would have been prohibitively slow. When we publish packages to npm, we replace these entry points with files in the [`/npm/`](https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/npm) folder that point to the build artifacts.
Not all packages have to be published on npm. For example, we keep some utilities that are tiny enough and can be safely duplicated in a [pseudo-package called `shared`](https://github.com/facebook/react/tree/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared). Our bundler is configured to [only treat `dependencies` declared from `package.json` as externals](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L326-L329) so it happily bundles the `shared` code into `react` and `react-dom` without leaving any references to `shared/` in the build artifacts. So you can use Yarn Workspaces even if you don't plan to publish actual npm packages!
### Removing the Custom Module System
In the past, we used a non-standard module system called "Haste" that lets you import any file from any other file by its unique `@providesModule` directive no matter where it is in the tree. It neatly avoids the problem of deep relative imports with paths like `../../../../` and is great for the product code. However, this makes it hard to understand the dependencies between packages. We also had to resort to hacks to make it work with different tools.
We decided to [remove Haste](https://github.com/facebook/react/pull/11303) and use the Node resolution with relative imports instead. To avoid the problem of deep relative paths, we have [flattened our repository structure](https://github.com/facebook/react/pull/11304) so that it goes at most one level deep inside each package:
```
|-react
| |-npm
| |-src
|-react-dom
| |-npm
| |-src
| | |-client
| | |-events
| | |-server
| | |-shared
```
This way, the relative paths can only contain one `./` or `../` followed by the filename. If one package needs to import something from another package, it can do so with an absolute import from a top-level entry point.
In practice, we still have [some cross-package "internal" imports](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-dom/src/client/ReactDOMFiberComponent.js#L10-L11) that violate this principle, but they're explicit, and we plan to gradually get rid of them.
## Compiling Flat Bundles
Historically, React was distributed in two different formats: as a single-file build that you can add as a `<script>` tag in the browser, and as a collection of CommonJS modules that you can bundle with a tool like webpack or Browserify.
Before React 16, each React source file had a corresponding CommonJS module that was published as part of the npm packages. Importing `react` or `react-dom` led bundlers to the package [entry point](https://unpkg.com/react@15/index.js) from which they would build a dependency tree with the CommonJS modules in the [internal `lib` folder](https://unpkg.com/react@15/lib/).
However, this approach had multiple disadvantages:
* **It was inconsistent.** Different tools produce bundles of different sizes for identical code importing React, with the difference going as far as 30 kB (before gzip).
* **It was inefficient for bundler users.** The code produced by most bundlers today contains a lot of "glue code" at the module boundaries. It keeps the modules isolated from each other, but increases the parse time, the bundle size, and the build time.
* **It was inefficient for Node users.** When running in Node, performing `process.env.NODE_ENV` checks before development-only code incurs the overhead of actually looking up environment variables. This slowed down React server rendering. We couldn't cache it in a variable either because it prevented dead code elimination with Uglify.
* **It broke encapsulation.** React internals were exposed both in the open source (as `react-dom/lib/*` imports) and internally at Facebook. It was convenient at first as a way to share utilities between projects, but with time it became a maintenance burden because renaming or changing argument types of internal functions would break unrelated projects.
* **It prevented experimentation.** There was no way for the React team to experiment with any advanced compilation techniques. For example, in theory, we might want to apply [Google Closure Compiler Advanced](https://developers.google.com/closure/compiler/docs/api-tutorial3) optimizations or [Prepack](https://prepack.io/) to some of our code, but they are designed to work on complete bundles rather than small individual modules that we used to ship to npm.
Due to these and other issues, we've changed the strategy in React 16. We still ship CommonJS modules for Node.js and bundlers, but instead of publishing many individual files in the npm package, we publish just two CommonJS bundles per entry point.
For example, when you import `react` with React 16, the bundler [finds the entry point](https://unpkg.com/react@16/index.js) that just re-exports one of the two files:
```js
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react.production.min.js');
} else {
module.exports = require('./cjs/react.development.js');
}
```
In every package provided by React, the [`cjs` folder](https://unpkg.com/react@16/cjs/) (short for "CommonJS") contains a development and a production pre-built bundle for each entry point.
For example, [`react.development.js`](https://unpkg.com/react@16/cjs/react.development.js) is the version intended for development. It is readable and includes comments. On the other hand, [`react.production.min.js`](https://unpkg.com/react@16/cjs/react.production.min.js) was minified and optimized before it was published to npm.
Note how this is essentially the same strategy that we've been using for the single-file browser builds (which now reside in the [`umd` directory](https://unpkg.com/react@16/umd/), short for [Universal Module Definition](https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/)). Now we just apply the same strategy to the CommonJS builds as well.
### Migrating to Rollup
Just compiling CommonJS modules into single-file bundles doesn't solve all of the above problems. The really significant wins came from [migrating our build system](https://github.com/facebook/react/pull/9327) from Browserify to [Rollup](https://rollupjs.org/).
[Rollup was designed with libraries rather than apps in mind](https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c), and it is a perfect fit for React's use case. It solves one problem well: how to combine multiple modules into a flat file with minimal junk code in between. To achieve this, instead of turning modules into functions like many other bundlers, it puts all the code in the same scope, and renames variables so that they don't conflict. This produces code that is easier for the JavaScript engine to parse, for a human to read, and for a minifier to optimize.
Rollup currently doesn't support some features that are important to application builders, such as code splitting. However, it does not aim to replace tools like webpack that do a great job at this. Rollup is a perfect fit for *libraries* like React that can be pre-built and then integrated into apps.
You can find our Rollup build configuration [here](https://github.com/facebook/react/blob/8ec146c38ee4f4c84b6ecf59f52de3371224e8bd/scripts/rollup/build.js#L336-L362), with a [list of plugins we currently use](https://github.com/facebook/react/blob/8ec146c38ee4f4c84b6ecf59f52de3371224e8bd/scripts/rollup/build.js#L196-L273).
### Migrating to Google Closure Compiler
After migrating to flat bundles, we [started](https://github.com/facebook/react/pull/10236) using [the JavaScript version of the Google Closure Compiler](https://github.com/google/closure-compiler-js) in its "simple" mode. In our experience, even with the advanced optimizations disabled, it still provided a significant advantage over Uglify, as it was able to better eliminate dead code and automatically inline small functions when appropriate.
At first, we could only use Google Closure Compiler for the React bundles we shipped in the open source. At Facebook, we still needed the checked-in bundles to be unminified so we could symbolicate React production crashes with our error reporting tools. We ended up contributing [a flag](https://github.com/google/closure-compiler/pull/2707) that completely disables the renaming compiler pass. This lets us apply other optimizations like function inlining, but keep the code fully readable for the Facebook-specific builds of React. To improve the output readability, we [also format that custom build using Prettier](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L249-L250). Interestingly, running Prettier on production bundles while debugging the build process is a great way to find unnecessary code in the bundles!
Currently, all production React bundles [run through Google Closure Compiler in simple mode](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L235-L248), and we may look into enabling advanced optimizations in the future.
### Protecting Against Weak Dead Code Elimination
While we use an efficient [dead code elimination](https://en.wikipedia.org/wiki/Dead_code_elimination) solution in React itself, we can't make a lot of assumptions about the tools used by the React consumers.
Typically, when you [configure a bundler for production](/docs/optimizing-performance.html#use-the-production-build), you need to tell it to substitute `process.env.NODE_ENV` with the `"production"` string literal. This process is sometimes called "envification". Consider this code:
```js
if (process.env.NODE_ENV !== "production") {
// development-only code
}
```
After envification, this condition will always be `false`, and can be completely eliminated by most minifiers:
```js
if ("production" !== "production") {
// development-only code
}
```
However, if the bundler is misconfigured, you can accidentally ship development code into production. We can't completely prevent this, but we took a few steps to mitigate the common cases when it happens.
#### Protecting Against Late Envification
As mentioned above, our entry points now look like this:
```js
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react.production.min.js');
} else {
module.exports = require('./cjs/react.development.js');
}
```
However, some bundlers process `require`s before envification. In this case, even if the `else` block never executes, the `cjs/react.development.js` file still gets bundled.
To prevent this, we also [wrap the whole content](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/rollup/wrappers.js#L65-L69) of the development bundle into another `process.env.NODE_ENV` check inside the `cjs/react.development.js` bundle itself:
```js
'use strict';
if (process.env.NODE_ENV !== "production") {
(function() {
// bundle code
})();
}
```
This way, even if the application bundle includes both the development and the production versions of the file, the development version will be empty after envification.
The additional [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression) wrapper is necessary because some declarations (e.g. functions) can't be placed inside an `if` statement in JavaScript.
#### Detecting Misconfigured Dead Code Elimination
Even though [the situation is changing](https://twitter.com/iamakulov/status/941336777188696066), many popular bundlers don't yet force the users to specify the development or production mode. In this case `process.env.NODE_ENV` is typically provided by a runtime polyfill, but the dead code elimination doesn't work.
We can't completely prevent React users from misconfiguring their bundlers, but we introduced a few additional checks for this in [React DevTools](https://github.com/facebook/react-devtools).
If the development bundle executes, [React DOM reports this to React DevTools](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/packages/react-dom/src/client/ReactDOM.js#L1333-L1335):
<br>
<img src="../images/docs/devtools-dev.png" style="max-width:100%" alt="React DevTools on a website with development version of React">
There is also one more bad scenario. Sometimes, `process.env.NODE_ENV` is set to `"production"` at runtime rather than at the build time. This is how it should work in Node.js, but it is bad for the client-side builds because the unnecessary development code is bundled even though it never executes. This is harder to detect but we found a heuristic that works well in most cases and doesn't seem to produce false positives.
We can write a function that contains a [development-only branch](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/packages/react-dom/npm/index.js#L11-L20) with an arbitrary string literal. Then, if `process.env.NODE_ENV` is set to `"production"`, we can [call `toString()` on that function](https://github.com/facebook/react-devtools/blob/b370497ba6e873c63479408f11d784095523a630/backend/installGlobalHook.js#L143) and verify that the string literal in the development-only has been stripped out. If it is still there, the dead code elimination didn't work, and we need to warn the developer. Since developers might not notice the React DevTools warnings on a production website, we also [throw an error inside `setTimeout`](https://github.com/facebook/react-devtools/blob/b370497ba6e873c63479408f11d784095523a630/backend/installGlobalHook.js#L153-L160) from React DevTools in the hope that it will be picked up by the error analytics.
We recognize this approach is somewhat fragile. The `toString()` method is not reliable and may change its behavior in future browser versions. This is why we put that logic into React DevTools itself rather than into React. This allows us to remove it later if it becomes problematic. We also warn only if we *found* the special string literal rather than if we *didn't* find it. This way, if the `toString()` output becomes opaque, or is overridden, the warning just won't fire.
## Catching Mistakes Early
We want to catch bugs as early as possible. However, even with our extensive test coverage, occasionally we make a blunder. We made several changes to our build and test infrastructure this year to make it harder to mess up.
### Migrating to ES Modules
With the CommonJS `require()` and `module.exports`, it is easy to import a function that doesn't really exist, and not realize that until you call it. However, tools like Rollup that natively support [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [`export`](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export) syntax fail the build if you mistype a named import. After releasing React 16, [we have converted the entire React source code](https://github.com/facebook/react/pull/11389) to the ES Modules syntax.
Not only did this provide some extra protection, but it also helped improve the build size. Many React modules only export utility functions, but CommonJS forced us to wrap them into an object. By turning those utility functions into named exports and eliminating the objects that contained them, we let Rollup place them into the top-level scope, and thus let the minifier mangle their names in the production builds.
For now, have decided to only convert the source code to ES Modules, but not the tests. We use powerful utilities like `jest.resetModules()` and want to retain tighter control over when the modules get initialized in tests. In order to consume ES Modules from our tests, we enabled the [Babel CommonJS transform](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/jest/preprocessor.js#L28-L29), but only for the test environment.
### Running Tests in Production Mode
Historically, we've been running all tests in a development environment. This let us assert on the warning messages produced by React, and seemed to make general sense. However, even though we try to keep the differences between the development and production code paths minimal, occasionally we would make a mistake in production-only code branches that weren't covered by tests, and cause an issue at Facebook.
To solve this problem, we have added a new [`yarn test-prod`](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/package.json#L110) command that runs on CI for every pull request, and [executes all React test cases in the production mode](https://github.com/facebook/react/pull/11616). We wrapped any assertions about warning messages into development-only conditional blocks in all tests so that they can still check the rest of the expected behavior in both environments. Since we have a custom Babel transform that replaces production error messages with the [error codes](/blog/2016/07/11/introducing-reacts-error-code-system.html), we also added a [reverse transformation](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/jest/setupTests.js#L91-L126) as part of the production test run.
### Using Public API in Tests
When we were [rewriting the React reconciler](https://code.facebook.com/posts/1716776591680069/react-16-a-look-inside-an-api-compatible-rewrite-of-our-frontend-ui-library/), we recognized the importance of writing tests against the public API instead of internal modules. If the test is written against the public API, it is clear what is being tested from the user's perspective, and you can run it even if you rewrite the implementation from scratch.
We reached out to the wonderful React community [asking for help](https://github.com/facebook/react/issues/11299) converting the remaining tests to use the public API. Almost all of the tests are converted now! The process wasn't easy. Sometimes a unit test just calls an internal method, and it's hard to figure out what the observable behavior from user's point of view was supposed to be tested. We found a few strategies that helped with this. The first thing we would try is to find the git history for when the test was added, and find clues in the issue and pull request description. Often they would contain reproducing cases that ended up being more valuable than the original unit tests! A good way to verify the guess is to try commenting out individual lines in the source code being tested. If the test fails, we know for sure that it stresses the given code path.
We would like to give our deepest thanks to [everyone who contributed to this effort](https://github.com/facebook/react/issues?q=is%3Apr+11299+is%3Aclosed).
### Running Tests on Compiled Bundles
There is also one more benefit to writing tests against the public API: now we can [run them against the compiled bundles](https://github.com/facebook/react/pull/11633).
This helps us ensure that tools like Babel, Rollup, and Google Closure Compiler don't introduce any regressions. This also opens the door for future more aggressive optimizations, as we can be confident that React still behaves exactly as expected after them.
To implement this, we have created a [second Jest config](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/jest/config.build.js). It overrides our default config but points `react`, `react-dom`, and other entry points to the `/build/packages/` folder. This folder doesn't contain any React source code, and reflects what gets published to npm. It is populated after you run `yarn build`.
This lets us run the same exact tests that we normally run against the source, but execute them using both development and production pre-built React bundles produced with Rollup and Google Closure Compiler.
Unlike the normal test run, the bundle test run depends on the build products so it is not great for quick iteration. However, it still runs on the CI server so if something breaks, the test will display as failed, and we will know it's not safe to merge into master.
There are still some test files that we intentionally don't run against the bundles. Sometimes we want to mock an internal module or override a feature flag that isn't exposed to the public yet. For those cases, we blacklist a test file by renaming it from `MyModule-test.js` to `MyModule-test.internal.js`.
Currently, over 93% out of 2,650 React tests run against the compiled bundles.
### Linting Compiled Bundles
In addition to linting our source code, we run a much more limited set of lint rules (really, [just two of them](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/validate/eslintrc.cjs.js#L26-L27)) on the compiled bundles. This gives us an extra layer of protection against regressions in the underlying tools and [ensures](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/validate/eslintrc.cjs.js#L22) that the bundles don't use any language features that aren't supported by older browsers.
### Simulating Package Publishing
Even running the tests on the built packages is not enough to avoid shipping a broken update. For example, we use the `files` field in our `package.json` files to specify a whitelist of folders and files that should be published on npm. However, it is easy to add a new entry point to a package but forget to add it to the whitelist. Even the bundle tests would pass, but after publishing the new entry point would be missing.
To avoid situations like this, we are now simulating the npm publish by [running `npm pack` and then immediately unpacking the archive](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/packaging.js#L129-L134) after the build. Just like `npm publish`, this command filters out anything that isn't in the `files` whitelist. With this approach, if we were to forget adding an entry point to the list, it would be missing in the build folder, and the bundle tests relying on it would fail.
### Creating Manual Test Fixtures
Our unit tests run only in the Node environment, but not in the browsers. This was an intentional decision because browser-based testing tools were flaky in our experience, and didn't catch many issues anyway.
We could get away with this because the code that touches the DOM is consolidated in a few files, and doesn't change that often. Every week, we update the Facebook.com codebase to the latest React commit on master. At Facebook, we use a set of internal [WebDriver](http://www.seleniumhq.org/projects/webdriver/) tests for critical product workflows, and these catch some regressions. React updates are first delivered to employees, so severe bugs get reported immediately before they reach two billion users.
Still, it was hard to review DOM-related changes, and occasionally we would make mistakes. In particular, it was hard to remember all the edge cases that the code had to handle, why they were added, and when it was safe to remove them. We considered adding some automatic tests that run in the browser but we didn't want to slow down the development cycle and deal with a fragile CI. Additionally, automatic tests don't always catch DOM issues. For example, an input value displayed by the browser may not match what it reports as a DOM property.
We've chatted about this with [Brandon Dail](https://github.com/aweary), [Jason Quense](https://github.com/jquense), and [Nathan Hunzaker](https://github.com/nhunzaker). They were sending substantial patches to React DOM but were frustrated that we failed to review them timely. We decided to give them commit access, but asked them to [create a set of manual tests](https://github.com/facebook/react/pull/8589) for DOM-related areas like input management. The initial set of manual fixtures [kept growing](https://github.com/facebook/react/commits/master/fixtures/dom) over the year.
These fixtures are implemented as a React app located in [`fixtures/dom`](https://github.com/facebook/react/tree/d906de7f602df810c38aa622c83023228b047db6/fixtures/dom). Adding a fixture involves writing a React component with a description of the expected behavior, and links to the appropriate issues and browser quirks, like [in this example](https://github.com/facebook/react/pull/11760):
<img src="https://user-images.githubusercontent.com/590904/33555298-dd52fb4e-d8cd-11e7-80e9-8369538eb633.png" style="max-width:100%" alt="DOM fixture example">
The fixture app lets you choose a version of React (local or one of the published versions) which is handy for comparing the behavior before and after the changes. When we change the behavior related to how we interact with the DOM, we can verify that it didn't regress by going through the related fixtures in different browsers.
In some cases, a change proved to be so complex that it necessitated a standalone purpose-built fixture to verify it. For example, the [DOM attribute handling in React 16](/blog/2017/09/08/dom-attributes-in-react-16.html) was very hard to pull off with confidence at first. We kept discovering different edge cases, and almost gave up on doing it in time for the React 16 release. However, then we've built an ["attribute table" fixture](https://github.com/facebook/react/tree/d906de7f602df810c38aa622c83023228b047db6/fixtures/attribute-behavior) that renders all supported attributes and their misspellings with previous and next version of React, and displays the differences. It took a few iterations (the key insight was to group attributes with similar behavior together) but it ultimately allowed us to fix all major issues in just a few days.
<br>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">We went through the table to vet the new behavior for every case (and discovered some old bugs too) <a href="https://t.co/cmF2qnK9Q9">pic.twitter.com/cmF2qnK9Q9</a></p>&mdash; Dan Abramov (@dan_abramov) <a href="https://twitter.com/dan_abramov/status/906244378066345984?ref_src=twsrc%5Etfw">September 8, 2017</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
Going through the fixtures is still a lot of work, and we are considering automating some of it. Still, the fixture app is invaluable even as documentation for the existing behavior and all the edge cases and browser bugs that React currently handles. Having it gives us confidence in making significant changes to the logic without breaking important use cases. Another improvement we're considering is to have a GitHub bot build and deploy the fixtures automatically for every pull request that touches the relevant files so anyone can help with browser testing.
### Preventing Infinite Loops
The React 16 codebase contains many `while` loops. They let us avoid the dreaded deep stack traces that occurred with earlier versions of React, but can make development of React really difficult. Every time there is a mistake in an exit condition our tests would just hang, and it took a while to figure out which of the loops is causing the issue.
Inspired by the [strategy adopted by Repl.it](https://repl.it/site/blog/infinite-loops), we have added a [Babel plugin that prevents infinite loops](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/babel/transform-prevent-infinite-loops.js) in the test environment. If some loop continues for more than the maximum allowed number of iterations, we throw an error and immediately fail it so that Jest can display where exactly this happened.
This approach has a pitfall. If an error thrown from the Babel plugin gets caught and ignored up the call stack, the test will pass even though it has an infinite loop. This is really, really bad. To solve this problem, we [set a global field](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/babel/transform-prevent-infinite-loops.js#L26-L30) before throwing the error. Then, after every test run, we [rethrow that error if the global field has been set](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/jest/setupTests.js#L42-L56). This way any infinite loop will cause a test failure, no matter whether the error from the Babel plugin was caught or not.
## Customizing the Build
There were a few things that we had to fine-tune after introducing our new build process. It took us a while to figure them out, but we're moderately happy with the solutions that we arrived at.
### Dead Code Elimination
The combination of Rollup and Google Closure Compiler already gets us pretty far in terms of stripping development-only code in production bundles. We [replace](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L223-L226) the `__DEV__` literal with a boolean constant during the build, and both Rollup together and Google Closure Compiler can strip out the `if (false) {}` code branches and even some more sophisticated patterns. However, there is one particularly nasty case:
```js
import warning from 'fbjs/lib/warning';
if (__DEV__) {
warning(false, 'Blimey!');
}
```
This pattern is very common in the React source code. However `fbjs/lib/warning` is an external import that isn't being bundled by Rollup for the CommonJS bundle. Therefore, even if `warning()` call ends up being removed, Rollup doesn't know whether it's safe to remove to the import itself. What if the module performs a side effect during initialization? Then removing it would not be safe.
To solve this problem, we use the [`treeshake.pureExternalModules` Rollup option](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L338-L340) which takes an array of modules that we can guarantee don't have side effects. This lets Rollup know that an import to `fbjs/lib/warning` is safe to completely strip out if its value is not being used. However, if it *is* being used (e.g. if we decide to add warnings in production), the import will be preserved. That's why this approach is safer than replacing modules with empty shims.
When we optimize something, we need to ensure it doesn't regress in the future. What if somebody introduces a new development-only import of an external module, and not realize they also need to add it to `pureExternalModules`? Rollup prints a warning in such cases but we've [decided to fail the build completely](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/build.js#L395-L412) instead. This forces the person adding a new external development-only import to [explicitly specify whether it has side effects or not](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/modules.js#L10-L22) every time.
### Forking Modules
In some cases, different bundles need to contain slightly different code. For example, React Native bundles have a different error handling mechanism that shows a redbox instead of printing a message to the console. However, it can be very inconvenient to thread these differences all the way through the calling modules.
Problems like this are often solved with runtime configuration. However, sometimes it is impossible: for example, the React DOM bundles shouldn't even attempt to import the React Native redbox helpers. It is also unfortunate to bundle the code that never gets used in a particular environment.
Another solution is to use dynamic dependency injection. However, it often produces code that is hard to understand, and may cause cyclical dependencies. It also defies some optimization opportunities.
From the code point of view, ideally we just want to "redirect" a module to its different "forks" for specific bundles. The "forks" have the exact same API as the original modules, but do something different. We found this mental model very intuitive, and [created a fork configuration file](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/forks.js) that specifies how the original modules map to their forks, and the conditions under which this should happen.
For example, this fork config entry specifies different [feature flags](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared/ReactFeatureFlags.js) for different bundles:
```js
'shared/ReactFeatureFlags': (bundleType, entry) => {
switch (entry) {
case 'react-native-renderer':
return 'shared/forks/ReactFeatureFlags.native.js';
case 'react-cs-renderer':
return 'shared/forks/ReactFeatureFlags.native-cs.js';
default:
switch (bundleType) {
case FB_DEV:
case FB_PROD:
return 'shared/forks/ReactFeatureFlags.www.js';
}
}
return null;
},
```
During the build, [our custom Rollup plugin](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/scripts/rollup/plugins/use-forks-plugin.js#L40) replaces modules with their forks if the conditions have matched. Since both the original modules and the forks are written as ES Modules, Rollup and Google Closure Compiler can inline constants like numbers or booleans, and thus efficiently eliminate dead code for disabled feature flags. In tests, when necessary, we [use `jest.mock()`](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/react-cs-renderer/src/__tests__/ReactNativeCS-test.internal.js#L15-L17) to point the module to the appropriate forked version.
As a bonus, we might want to verify that the export types of the original modules match the export types of the forks exactly. We can use a [slightly odd but totally working Flow trick](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared/forks/ReactFeatureFlags.native.js#L32-L36) to accomplish this:
```js
import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as FeatureFlagsShimType from './ReactFeatureFlags.native';
type Check<_X, Y: _X, X: Y = _X> = null;
(null: Check<FeatureFlagsShimType, FeatureFlagsType>);
```
This works by essentially forcing Flow to verify that two types are assignable to each other (and thus are equivalent). Now if we modify the exports of either the original module or the fork without changing the other file, the type check will fail. This might be a little goofy but we found this helpful in practice.
To conclude this section, it is important to note that you can't specify your own module forks if you consume React from npm. This is intentional because none of these files are public API, and they are not covered by the [semver](https://semver.org/) guarantees. However, you are always welcome to build React from master or even fork it if you don't mind the instability and the risk of divergence. We hope that this writeup was still helpful in documenting one possible approach to targeting different environments from a single JavaScript library.
### Tracking Bundle Size
As a final build step, we now [record build sizes for all bundles](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/rollup/build.js#L264-L272) and write them to a file that [looks like this](https://github.com/facebook/react/blob/d906de7f602df810c38aa622c83023228b047db6/scripts/rollup/results.json). When you run `yarn build`, it prints a table with the results:
<br>
<img src="https://user-images.githubusercontent.com/1519870/28427900-80487dbc-6d6f-11e7-828d-1b594bd1ddb5.png" style="max-width:100%" alt="Build results after running GCC">
*(It doesn't always look as good as this. This was the commit that migrated React from Uglify to Google Closure Compiler.)*
Keeping the file sizes committed for everyone to see was helpful for tracking size changes and motivating people to find optimization opportunities.
We haven't been entirely happy with this strategy because the JSON file often causes merge conflicts on larger branches. Updating it is also not currently enforced so it gets out of date. In the future, we're considering integrating a bot that would comment on pull requests with the size changes.
## Simplifying the Release Process
We like to release updates to the open source community often. Unfortunately, the old process of creating a release was slow and would typically take an entire day. After some changes to this process, we're now able to do a full release in less than an hour. Here's what we changed.
### Branching Strategy
Most of the time spent in the old release process was due to our branching strategy. The `master` branch was assumed to be unstable and would often contain breaking changes. Releases were done from a `stable` branch, and changes were manually cherry-picked into this branch prior to a release. We had [tooling to help automate](https://github.com/facebook/react/pull/7330) some of this process, but it was still [pretty complicated to use](https://github.com/facebook/react/blob/b5a2a1349d6e804d534f673612357c0be7e1d701/scripts/release-manager/Readme.md).
As of version 16, we now release from the `master` branch. Experimental features and breaking changes are allowed, but must be hidden behind [feature flags](https://github.com/facebook/react/blob/cc52e06b490e0dc2482b345aa5d0d65fae931095/packages/shared/ReactFeatureFlags.js) so they can be removed during the build process. The new flat bundles and dead code elimination make it possible for us to do this without fear of leaking unwanted code into open source builds.
### Automated Scripts
After changing to a stable `master`, we created a new [release process checklist](https://github.com/facebook/react/issues/10620). Although much simpler than the previous process, this still involved dozens of steps and forgetting one could result in a broken release.
To address this, we created a new [automated release process](https://github.com/facebook/react/pull/11223) that is [much easier to use](https://github.com/facebook/react/tree/master/scripts/release#react-release-script) and has several built-in checks to ensure that we release a working build. The new process is split into two steps: _build_ and _publish_. Here's what it looks like the first time you run it:
![Release Script overview](../images/blog/release-script-build-overview.png)
The _build_ step does most of the work- verifying permissions, running tests, and checking CI status. Once it finishes, it prints a reminder to update the CHANGELOG and to verify the bundle using the [manual fixtures](#creating-manual-test-fixtures) described above.
![Release Script build confirmation screen](../images/blog/release-script-build-confirmation.png)
All that's left is to tag and publish the release to NPM using the _publish_ script.
![Release Script publish confirmation screen](../images/blog/release-script-publish-confirmation.png)
(You may have noticed a `--dry` flag in the screenshots above. This flag allows us to run a release, end-to-end, without actually publishing to NPM. This is useful when working on the release script itself.)
## In Conclusion
Did this post inspire you to try some of these ideas in your own projects? We certainly hope so! If you have other ideas about how React build, test, or contribution workflow could be improved, please let us know on [our issue tracker](https://github.com/facebook/react/issues).
You can find the related issues by the [build infrastructure label](https://github.com/facebook/react/labels/Component%3A%20Build%20Infrastructure). These are often great first contribution opportunities!
## Acknowledgements
We would like to thank:
* [Rich Harris](https://github.com/Rich-Harris) and [Lukas Taegert](https://github.com/lukastaegert) for maintaining Rollup and helping us integrate it.
* [Dimitris Vardoulakis](https://github.com/dimvar), [Chad Killingsworth](https://github.com/ChadKillingsworth), and [Tyler Breisacher](https://github.com/MatrixFrog) for their work on Google Closure Compiler and timely advice.
* [Adrian Carolli](https://github.com/watadarkstar), [Adams Au](https://github.com/rivenhk), [Alex Cordeiro](https://github.com/accordeiro), [Jordan Tepper](https://github.com/HeroProtagonist), [Johnson Shi](https://github.com/sjy), [Soo Jae Hwang](https://github.com/misoguy), [Joe Lim](https://github.com/xjlim), [Yu Tian](https://github.com/yu-tian113), and others for helping prototype and implement some of these and other improvements.
* [Anushree Subramani](https://github.com/anushreesubramani), [Abid Uzair](https://github.com/abiduzz420), [Sotiris Kiritsis](https://github.com/skiritsis), [Tim Jacobi](https://github.com/timjacobi), [Anton Arboleda](https://github.com/aarboleda1), [Jeremias Menichelli](https://github.com/jeremenichelli), [Audy Tanudjaja](https://github.com/audyodi), [Gordon Dent](https://github.com/gordyd), [Iacami Gevaerd
](https://github.com/enapupe), [Lucas Lentz](https://github.com/sadpandabear), [Jonathan Silvestri](https://github.com/silvestrijonathan), [Mike Wilcox](https://github.com/mjw56), [Bernardo Smaniotto](https://github.com/smaniotto), [Douglas Gimli](https://github.com/douglasgimli), [Ethan Arrowood](https://github.com/ethan-arrowood), and others for their help porting the React test suite to use the public API.

10
content/community/conferences.md

@ -16,6 +16,11 @@ December 2, Berlin, Germany
[Website](https://reactday.berlin) - [Twitter](https://twitter.com/reactdayberlin) - [Facebook](https://www.facebook.com/reactdayberlin/)
### ReactFoo Pune
January 19-20, Pune, India
[Website](https://reactfoo.in/2018-pune/) - [Twitter](https://twitter.com/ReactFoo)
### AgentConf 2018
January 25-28 in Dornbirn, Austria
@ -31,6 +36,11 @@ May 17-18 in Paris, France
[Website](https://www.react-europe.org) - [Twitter](https://twitter.com/ReactEurope) - [Facebook](https://www.facebook.com/ReactEurope)
### React Rally
August 16-17 in Salt Lake City, Utah USA
[Website](http://www.reactrally.com) - [Twitter](https://twitter.com/reactrally)
### ReactNext 2018
September 6 in Tel Aviv, Israel

4
content/community/courses.md

@ -16,6 +16,10 @@ permalink: community/courses.html
- [The Road to Learn React](https://www.robinwieruch.de/the-road-to-learn-react/) - Build a real world application in plain React without complicated tooling.
- [React Training: React Patterns](https://reacttraining.com/patterns/) - Free lectures from React Training's "Advanced React.js" course.
- [Egghead.io: The Beginner's Guide to ReactJS](https://egghead.io/courses/the-beginner-s-guide-to-reactjs) - Free course for React newbies and those looking to get a better understanding of React fundamentals.
## Paid Courses
- [Egghead.io](https://egghead.io/browse/frameworks/react) - Short instructional videos on React and many other topics.

2
content/community/examples.md

@ -20,3 +20,5 @@ There are many example projects created by the React community. Feel free to add
* **[Product Comparison Page](https://github.com/Rhymond/product-compare-react)** Simple Product Compare page built in React
* **[Hacker News Clone React/GraphQL](https://github.com/clintonwoo/hackernews-react-graphql)** Hacker News clone rewritten with universal JavaScript, using React and GraphQL.
* **[Reddit Mobile](https://github.com/reddit/reddit-mobile)** Reddit's mobile platform.
* **[Bitcoin Price Index (powered by CoinDesk)](http://bitcoinpriceindex.netlify.com)** Simple bitcoin price index data from CoinDesk API.
* **[Public APIs curated by toddmotto](https://publicapis.netlify.com/)** A collective list of public JSON APIs for use in web development.

3
content/community/meetups.md

@ -24,6 +24,8 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet
* [São Paulo](http://www.meetup.com/pt-BR/ReactJS-SP/)
## Canada
* [Montreal, QC - ReactJS](https://www.meetup.com/fr-FR/ReactMontreal/)
* [Montreal, QC - React Native](https://www.meetup.com/fr-FR/React-Native-MTL/)
* [Vancouver, BC](http://www.meetup.com/ReactJS-Vancouver-Meetup/)
## China
@ -45,6 +47,7 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet
## Germany
* [Berlin](http://www.meetup.com/React-Berlin/)
* [Hamburg](http://www.meetup.com/Hamburg-React-js-Meetup/)
* [Karlsruhe](http://www.meetup.com/react_ka/)
* [Munich](http://www.meetup.com/ReactJS-Meetup-Munich/)
## Greece

3
content/community/tools-comp-workbenches.md

@ -5,9 +5,10 @@ layout: community
permalink: community/component-workbenches.html
---
* **[React Storybook](https://github.com/kadirahq/react-storybook):** UI component development environment for React.
* **[Storybook for React](https://github.com/storybooks/storybook):** UI component development environment for React.
* **[React Styleguidist](https://github.com/styleguidist/react-styleguidist):** Style guide generator & component workbench for React.
* **[React Showroom](https://github.com/OpusCapita/react-showroom-client):** React based components catalog which provides you with markdown documentation and live examples
* **[patternplate](https://github.com/sinnerschrader/patternplate)**: A platform for pattern and component library development using React.
* **[UiZoo.js](https://github.com/myheritage/UiZoo.js)**: Auto-generated component development environment by the JSDoc of React components.
* **[Neutrino React components preset](https://github.com/eliperelman/neutrino-preset-react-components/)**: Create generic React components and previewing them without the need to embed in an application. Plays nicely with other Neutrino middleware, so you can build, test, preview, and publish multiple React components from a single repository.
* **[React Cosmos](https://github.com/react-cosmos/react-cosmos)**: Dev tool for creating reusable React components. It scans your project for components and enables you to: render components in different states, mock dependencies (API, localStorage, etc.), see app state evolve in real time.

18
content/community/tools-starter-kits.md

@ -5,20 +5,34 @@ layout: community
permalink: community/starter-kits.html
---
## Recommended by the React Team
* **[Create React App](https://github.com/facebookincubator/create-react-app)** - An officially supported way to start a client-side React project with no configuration
* **[Next.js](https://learnnextjs.com/)** - Framework for server-rendered or statically-exported React apps
* **[Gatsby](https://www.gatsbyjs.org/)** - Blazing-fast static site generator for React
* **[nwb](https://github.com/insin/nwb)** - A toolkit for React apps, libraries and other npm modules for the web
* **[razzle](https://github.com/jaredpalmer/razzle)** - Create server-rendered universal JavaScript applications with no configuration
* **[Neutrino](https://neutrino.js.org/)** - Create and build modern JavaScript applications with zero initial configuration
## Client-side Kits
* **[kyt](https://github.com/nytimes/kyt)** - The framework that the New York Times uses to develop and build their web properties. It's somewhat opinionated but configurable, and includes starter kits with options to build full-stack or static/client-side apps with the following tools: Express, React, static assets, latest ES, CSS/Sass Modules, Jest, code-splitting, ESLint/Prettier, StyleLint, PostCSS, and inline SVGs.
* **[React CDK](https://github.com/kadirahq/react-cdk)** - Component Development Kit for React
* **[React Static Boilerplate](https://github.com/koistya/react-static-boilerplate):** Static site generator based on React.js, Gulp/Webpack, React Hot Loader, Babel, postCSS/cssnext. Best suited for deploying React.js site to GitHub Pages or Amazon S3.
* **[React Static Boilerplate](https://github.com/koistya/react-static-boilerplate):** Static site generator based on React, Gulp/Webpack, React Hot Loader, Babel, postCSS/cssnext. Best suited for deploying React.js site to GitHub Pages or Amazon S3.
* **[React Redux Boilerplate](https://github.com/iroy2000/react-redux-boilerplate):** React Redux Boilerplate is a workflow boilerplate that make life easier for developers by providing a virtual development environment and production ready build workflow out of the box. ( React, Redux, Reselect, Redux Actions, ES6, ESLint, Webpack with integrated environment config support )
* **[Create React App + Redux + React Router](https://github.com/notrab/create-react-app-redux)**: Based on Create React App, this boilerplate comes with Redux, Redux Thunk and React Router all configured ready to go.
* **[React, TypeScript, JSPM starter-kit](https://github.com/piotrwitek/react-ts-jspm-starter-kit):** Unopinionated starter kit to build modular web apps with React & TypeScript powered by JSPM/SystemJS 0.17.X (ES2016, hot-reload, browser-sync, bundle for prod scripts)
* **[Subschema](https://subschema.github.io/subschema)** - Subschema is a Dependency Injection Library for React, included is a project starter, with webpack, karma and babel.
* **[React + Redux + Saga Boilerplate](https://github.com/gilbarbara/react-redux-saga-boilerplate)** -
Ready to grow boilerplate with react-router, redux, saga, webpack 2, jest w/ coverage and enzyme.
* **[generator-enigma](https://www.npmjs.com/package/generator-enigma)** a minimalist React application scaffolding tool that sets up a ready-to-deploy web app, complete with testing via Jest and optional `react-router` boilerplate.
* **[Component-Template](https://github.com/reactstrap/component-template)** - A create-react-app based starter kit for building, documenting, & publishing React Components. Includes React Router v4, Bootstrap 4 and Reactstrap.
* **[Rekit](https://github.com/supnate/rekit)** - Toolkit and boilerplates for building scalable web applications with React, Redux and React-router.
* **[webcube](https://github.com/dexteryy/Project-WebCube)** - A JS infrastructure for modern Universal JS web app/sites and static websites. Provides built-in support and simplification for Redux sub-app, reducer bundle, router, immutable, eslint + prettier, docker, monorepo and many other tools.
## Full-stack Kits
* **[kyt](https://github.com/nytimes/kyt)** - The framework that the New York Times uses to develop and build their web properties. It's somewhat opinionated but configurable, and includes starter kits with options to build full-stack or static/client-side apps with the following tools: Express, React, static assets, latest ES, CSS/Sass Modules, Jest, code-splitting, ESLint/Prettier, StyleLint, PostCSS, and inline SVGs.
* **[react-universally](https://github.com/ctrlplusb/react-universally)** A starter kit for universal react applications with React, Express, React Router (v4), ES2017, Flow, Jest, Service workers, Data-fetching and code-splitting.
* **[web-service-template](https://github.com/nandai/web-service-template)** Membership single-page application with React and TypeScript.
* **[starter-react-flux](https://github.com/SokichiFujita/starter-react-flux)** A generator for React and Flux project with Flux-Utils, Jest, Immutable.js, React Addons, Webpack, ESLint, Babel and ES2015.
@ -78,3 +92,5 @@ Gulp, NPM, Browserify, React, Phonegap, Less, Recess, Underscore, JQuery...
* **[react-redux-universal-boilerplate](https://github.com/kiki-le-singe/react-redux-universal-boilerplate):**
An Universal ReactJS/Redux Boilerplate with Babel, Webpack 2, Webpack backend bundling, React Hot Loader 3, sass or cssnext, testing, linting...
* **[FUJITSU K5 Playground](https://playground.cloud.global.fujitsu.com)** A SPA and BFF generator with React, Flux, Swagger, Node.js, Material-ui, Jest, Webpack, ESLint and Babel.
* **[CRA Universal CLI](https://github.com/antonybudianto/cra-universal)** CLI to initialize universal create-react-app without ejecting. Supports Server-side rendering with Code-splitting, and Node Stream rendering.
* **[EDGE Platform](https://github.com/sebastian-software/edge)** Universal React/SSR + Apollo GraphQL + JS/CSS Code Splitting + Fine-Tuned Webpack + Localization/Internationalization. Most things are external dependencies. Boilerplate available.

5
content/community/tools-ui-components.md

@ -1,6 +1,6 @@
---
id: ui-components
title: UI Componets
title: UI Components
layout: community
permalink: community/ui-components.html
---
@ -33,7 +33,6 @@ permalink: community/ui-components.html
* **[react-document-title](https://github.com/gaearon/react-document-title)** Declarative, nested, stateful, isomorphic document.title for React
* **[react-dropzone](https://github.com/felixrieseberg/React-Dropzone):** React Dropzone for File-Uploads
* **[react-forms](http://prometheusresearch.github.io/react-forms/):** Form rendering and validation for React
*
* **[react-highlight](https://github.com/akiran/react-highlight):** React component for syntax highlighting
* **[react-image](https://github.com/yuanyan/react-image):** Like `<img />` and Enhanced Image Component for React.
* **[react-input-autosize](https://github.com/JedWatson/react-input-autosize):** Like `<input />` but resizes automatically to fit all its content.
@ -42,7 +41,6 @@ permalink: community/ui-components.html
* **[react-ladda](https://github.com/jsdir/react-ladda):** React wrapper for Ladda buttons.
* **[react-lorem-component](https://github.com/martinandert/react-lorem-component):** Lorem Ipsum placeholder component.
* **[react-notification](https://github.com/pburtchaell/react-notification):** Snackbar style notifications
*
* **[react-select](https://github.com/JedWatson/react-select):** Native React Select / Multiselect input field, similar to Selectize / Chosen / Select2
* **[react-selectize](https://furqanzafar.github.io/react-selectize/):** A stateless & flexible Select component, designed as a drop in replacement for React.DOM.Select, inspired by Selectize
* **[react-sigma](https://www.npmjs.com/package/react-sigma)**: Lightweight but powerful library for drawing network graphs
@ -52,6 +50,7 @@ permalink: community/ui-components.html
* **[react-switch-button](https://github.com/gfazioli/react-switch-button):** Beautiful React Switch button component
* **[react-tappable](https://github.com/JedWatson/react-tappable)** A Tappable React Component that provides native-feeling onTap events for mobile React apps
* **[react-textarea-autosize](https://github.com/andreypopp/react-textarea-autosize):** Like `<textarea />` but resizes automatically to fit all its content.
* **[react-toastify](https://github.com/fkhadra/react-toastify):** React notification made easy
* **[React-TimeAgo](https://www.npmjs.org/package/react-timeago)** A minimal live updating Time Ago component that smartly converts any time to a 'ago' or 'from now' format and keeps it updated.
* **[react-translate-component](https://github.com/martinandert/react-translate-component):** React component for i18n.
* **[react-treeview](https://github.com/chenglou/react-treeview):** Easy, light, flexible tree view.

66
content/docs/accessibility.md

@ -39,6 +39,48 @@ Note that all `aria-*` HTML attributes are fully supported in JSX. Whereas most
/>
```
## Semantic HTML
Semantic HTML is the foundation of accessibility in a web application. Using the various HTML elements to reinforce the meaning of information
in our websites will often give us accessibility for free.
- [MDN HTML elements reference](https://developer.mozilla.org/en-US/docs/Web/HTML/Element)
Sometimes we break HTML semantics when we add `<div>` elements to our JSX to make our React code work, especially when working with lists (`<ol>`, `<ul>` and `<dl>`) and the HTML `<table>`.
In these cases we should rather use React Fragments to group together multiple elements.
Use `<Fragment>` when a `key` prop is required:
```javascript{1,8,11}
import React, { Fragment } from 'react';
function Glossary(props) {
return (
<dl>
{props.items.map(item => (
// Without the `key`, React will fire a key warning
<Fragment key={item.id}>
<dt>{item.term}</dt>
<dd>{item.description}</dd>
</Fragment>
)}
</dl>
);
}
```
Use `<></>` syntax everywhere else:
```javascript
function ListItem({ item }) {
return (
<>
<dt>{item.term}</dt>
<dd>{item.description}</dd>>
</>
);
}
```
## Accessible Forms
### Labeling
@ -100,7 +142,7 @@ we need to programmatically nudge the keyboard focus in the right direction. For
The Mozilla Developer Network takes a look at this and describes how we can build [keyboard-navigable JavaScript widgets](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Keyboard-navigable_JavaScript_widgets).
To set focus in React, we can use [Refs to Components](refs-and-the-dom.html).
To set focus in React, we can use [Refs to DOM elements](refs-and-the-dom.html).
Using this, we first create a ref to an element in the JSX of a component class:
@ -124,6 +166,28 @@ Then we can focus it elsewhere in our component when needed:
this.textInput.focus();
}
```
Sometimes a parent component needs to set focus to an element in a child component. Although we can create [refs to class components](refs-and-the-dom.html#adding-a-ref-to-a-class-component),
we need a pattern that also works with functional components and when [using refs with HOCs](higher-order-components.html#refs-arent-passed-through).
To ensure that our parent component can always access the ref, we pass a callback as a prop to the child component to [expose the ref to the parent component](refs-and-the-dom.html#exposing-dom-refs-to-parent-components).
```js
// Expose the ref with a callback prop
function Field({ inputRef, ...rest }) {
return <input ref={inputRef} {...rest} />;
}
// Inside a parent class component's render method...
<Field
inputRef={(inputEl) => {
// This callback gets passed through as a regular prop
this.inputEl = inputEl
}}
/>
// Now you can set focus when required.
this.inputEl.focus();
```
A great focus management example is the [react-aria-modal](https://github.com/davidtheclark/react-aria-modal). This is a relatively rare example of a fully accessible modal window. Not only does it set initial focus on
the cancel button (preventing the keyboard user from accidentally activating the success action) and trap keyboard focus inside the modal, it also resets focus back to the element that

6
content/docs/addons-create-fragment.md

@ -6,7 +6,11 @@ layout: docs
category: Add-Ons
---
**Importing**
> Note:
>
> `React.addons` entry point is deprecated as of React v15.5. We now have first class support for fragments which you can read about [here](/docs/fragments.html).
## Importing
```javascript
import createFragment from 'react-addons-create-fragment'; // ES6

2
content/docs/components-and-props.md

@ -198,7 +198,7 @@ function Comment(props) {
}
```
Next, we will extract a `UserInfo` component that renders an `Avatar` next to user's name:
Next, we will extract a `UserInfo` component that renders an `Avatar` next to the user's name:
```js{3-8}
function UserInfo(props) {

2
content/docs/composition-vs-inheritance.md

@ -79,7 +79,7 @@ function App() {
[Try it on CodePen.](https://codepen.io/gaearon/pen/gwZOJp?editors=0010)
React elements like `<Contacts />` and `<Chat />` are just objects, so you can pass them as props like any other data.
React elements like `<Contacts />` and `<Chat />` are just objects, so you can pass them as props like any other data. This approach may remind you of "slots" in other libraries but there are no limitations on what you can pass as props in React.
## Specialization

77
content/docs/faq-functions.md

@ -117,7 +117,7 @@ Make sure you aren't _calling the function_ when you pass it to the component:
```jsx
render() {
// Wrong: handleClick is called instead of passed as a reference!
return <button onClick={this.handleClick()}>Click Me</button>
return <button onClick={this.handleClick()}>Click Me</button>
}
```
@ -126,13 +126,13 @@ Instead, *pass the function itself* (without parens):
```jsx
render() {
// Correct: handleClick is passed as a reference!
return <button onClick={this.handleClick}>Click Me</button>
return <button onClick={this.handleClick}>Click Me</button>
}
```
### How do I pass a parameter to an event handler or callback?
You can use an arrow function to wrap around an event handler and pass parameters:
You can use an arrow function to wrap around an event handler and pass parameters:
```jsx
<button onClick={() => this.handleClick(id)} />
@ -166,14 +166,14 @@ class Alphabet extends React.Component {
<div>
Just clicked: {this.state.justClicked}
<ul>
{this.state.letters.map(letter =>
{this.state.letters.map(letter =>
<li key={letter} onClick={() => this.handleClick(letter)}>
{letter}
</li>
)}
</ul>
</div>
)
)
}
}
```
@ -200,31 +200,37 @@ class Alphabet extends React.Component {
justClicked: e.target.dataset.letter
});
}
render() {
return (
<div>
Just clicked: {this.state.justClicked}
<ul>
{this.state.letters.map(letter =>
{this.state.letters.map(letter =>
<li key={letter} data-letter={letter} onClick={this.handleClick}>
{letter}
</li>
)}
</ul>
</div>
)
)
}
}
```
### How can I prevent a function from being called too quickly or too many times in a row?
If you have an event handler such as `onClick` or `onScroll` and want to prevent the callback from being fired too quickly, you can wrap the handler with a utility such as [`_.debounce`](https://lodash.com/docs#debounce) or [`_.throttle`](https://lodash.com/docs#throttle). See [this visualization](http://demo.nimius.net/debounce_throttle/) for a comparison of the two.
If you have an event handler such as `onClick` or `onScroll` and want to prevent the callback from being fired too quickly, then you can limit the rate at which callback is executed. This can be done by using:
- **throttling**: sample changes based on a time based frequency (eg [`_.throttle`](https://lodash.com/docs#throttle))
- **debouncing**: publish changes after a period of inactivity (eg [`_.debounce`](https://lodash.com/docs#debounce))
- **`requestAnimationFrame` throttling**: sample changes based on [`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) (eg [`raf-schd`](https://github.com/alexreardon/raf-schd))
See [this visualization](http://demo.nimius.net/debounce_throttle/) for a comparison of `throttle` and `debounce` functions.
> Note:
>
> Both `_.debounce` and `_.throttle` provide a `cancel` method to cancel delayed callbacks. You should either call this method from `componentWillUnmount` _or_ check to ensure that the component is still mounted within the delayed function.
> `_.debounce`, `_.throttle` and `raf-schd` provide a `cancel` method to cancel delayed callbacks. You should either call this method from `componentWillUnmount` _or_ check to ensure that the component is still mounted within the delayed function.
#### Throttle
@ -295,3 +301,54 @@ class Searchbox extends React.Component {
}
}
```
#### `requestAnimationFrame` throttling
[`requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) is a way of queuing a function to be executed in the browser at the optimal time for rendering performance. A function that is queued with `requestAnimationFrame` will fire in the next frame. The browser will work hard to ensure that there are 60 frames per second (60 fps). However, if the browser is unable to it will naturally *limit* the amount of frames in a second. For example, a device might only be able to handle 30 fps and so you will only get 30 frames in that second. Using `requestAnimationFrame` for throttling is a useful technique in that it prevents you from doing more than 60 updates in a second. If you are doing 100 updates in a second this creates additional work for the browser that the user will not see anyway.
>**Note:**
>
>Using this technique will only capture the last published value in a frame. You can see an example of how this optimization works on [`MDN`](https://developer.mozilla.org/en-US/docs/Web/Events/scroll)
```jsx
import rafSchedule from 'raf-schd';
class ScrollListener extends React.Component {
constructor(props) {
super(props);
this.handleScroll = this.handleScroll.bind(this);
// Create a new function to schedule updates.
this.scheduleUpdate = rafSchedule(
point => this.props.onScroll(point)
);
}
handleScroll(e) {
// When we receive a scroll event, schedule an update.
// If we receive many updates within a frame, we'll only publish the latest value.
this.scheduleUpdate({ x: e.clientX, y: e.clientY });
}
componentWillUnmount() {
// Cancel any pending updates since we're unmounting.
this.scheduleUpdate.cancel();
}
render() {
return (
<div
style={{ overflow: 'scroll' }}
onScroll={this.handleScroll}
>
<img src="/my-huge-image.jpg" />
</div>
);
}
}
```
#### Testing your rate limiting
When testing your rate limiting code works correctly it is helpful to have the ability to fast forward time. If you are using [`jest`](https://facebook.github.io/jest/) then you can use [`mock timers`](https://facebook.github.io/jest/docs/en/timer-mocks.html) to fast forward time. If you are using `requestAnimationFrame` throttling then you may find [`raf-stub`](https://github.com/alexreardon/raf-stub) to be a useful tool to control the ticking of animation frames.

8
content/docs/faq-state.md

@ -10,6 +10,14 @@ category: FAQ
`setState()` schedules an update to a component's `state` object. When state changes, the component responds by re-rendering.
### What is the difference between state and props?
[`props`](/docs/components-and-props.html) (short for "properties") and [`state`](/docs/state-and-lifecycle.html) are both just JavaScript objects that trigger a re-render when changed. While both hold information that influences the output of render, they are different in one important way: `props` get passed to the component (similar to function parameters) whereas `state` is managed within the component (similar to variables declared within a function).
Here are some good resources for further reading on when to use `props` vs `state`:
* [Props vs State](https://github.com/uberVU/react-guide/blob/master/props-vs-state.md)
* [ReactJS: Props vs. State](http://lucybain.com/blog/2016/react-state-vs-pros/)
### Why is `setState` is giving me the wrong value?
Calls to `setState` are asynchronous - don't rely on `this.state` to reflect the new value immediately after calling `setState`. Pass an updater function instead of an object if you need compute values based on the current state (see below for details).

67
content/docs/faq-structure.md

@ -8,18 +8,67 @@ category: FAQ
### Is there a recommended way to structure React projects?
React doesn't have opinions on how you put files into folders. That said there are a few common approaches popular in the ecosystem you may want to consider.
#### Grouping by features or routes
One common way to structure projects is locate CSS, JS, and tests together inside folders grouped by feature or route.
```
FeatureA
common/
Avatar.js
Avatar.css
APIUtils.js
APIUtils.test.js
feed/
index.js
ComponentA.js
ComponentA.css
ComponentA.test.js
Helper.js
Helper.test.js
FeatureB
Feed.js
Feed.css
FeedStory.js
FeedStory.test.js
FeedAPI.js
profile/
index.js
ComponentB.js
ComponentB.test.js
Profile.js
ProfileHeader.js
ProfileHeader.css
ProfileAPI.js
```
The definition of a "feature" is not universal, and it is up to you to choose the granularity. If you can't come up with a list of top-level folders, you can ask the users of your product what major parts it consists of, and use their mental model as a blueprint.
#### Grouping by file type
Another popular way to structure projects is to group similar files together, for example:
```
api/
APIUtils.js
APIUtils.test.js
ProfileAPI.js
UserAPI.js
components/
Avatar.js
Avatar.css
Feed.js
Feed.css
FeedStory.js
FeedStory.test.js
Profile.js
ProfileHeader.js
ProfileHeader.css
```
Some people also prefer to go further, and separate components into different folders depending on their role in the application. For example, [Atomic Design](http://bradfrost.com/blog/post/atomic-web-design/) is a design methodology built on this principle. Remember that it's often more productive to treat such methodologies as helpful examples rather than strict rules to follow.
#### Avoid too much nesting
There are many pain points associated with deep directory nesting in JavaScript projects. It becomes harder to write relative imports between them, or to update those imports when the files are moved. Unless you have a very compelling reason to use a deep folder structure, consider limiting yourself to a maximum of three or four nested folders within a single project. Of course, this is only a recommendation, and it may not be relevant to your project.
#### Don't overthink it
If you're just starting a project, [don't spend more than five minutes](https://en.wikipedia.org/wiki/Analysis_paralysis) on choosing a file structure. Pick any of the above approaches (or come up with your own) and start writing code! You'll likely want to rethink it anyway after you've written some real code.
If you feel completely stuck, start by keeping all files in a single folder. Eventually it will grow large enough that you will want to separate some files from the rest. By that time you'll have enough knowledge to tell which files you edit together most often. In general, it is a good idea to keep files that often change together close to each other. This principle is called "colocation".
As projects grow larger, they often use a mix of both of the above approaches in practice. So choosing the "right" one in the beginning isn't very important.

4
content/docs/faq-styling.md

@ -40,9 +40,9 @@ CSS classes are generally more efficient than inline styles.
### What is CSS-in-JS?
CSS-in-JS refers to a pattern where CSS is written with Javascript, then extracted into a stylesheet.
"CSS-in-JS" refers to a pattern where CSS is composed using JavaScript instead of defined in external files. Read a comparison of CSS-in-JS libraries [here](https://github.com/MicheleBertoli/css-in-js).
[Comparison of CSS-in-JS Libraries](https://github.com/MicheleBertoli/css-in-js)
_Note that this functionality is not a part of React, but provided by third-party libraries._ React does not have an opinion about how styles are defined; if in doubt, a good starting point is to define your styles in a separate `*.css` file as usual and refer to them using [`className`](/docs/dom-elements.html#classname).
### Can I do animations in React?

2
content/docs/forms.md

@ -113,7 +113,7 @@ class EssayForm extends React.Component {
return (
<form onSubmit={this.handleSubmit}>
<label>
Name:
Essay:
<textarea value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />

142
content/docs/fragments.md

@ -0,0 +1,142 @@
---
id: fragments
title: Fragments
permalink: docs/fragments.html
---
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.
```js
render() {
return (
<React.Fragment>
<ChildA />
<ChildB />
<ChildC />
</React.Fragment>
);
}
```
There is also a new [short syntax](#short-syntax) for declaring them, but it isn't supported by all popular tools yet.
## Motivation
A common pattern is for a component to return a list of children. Take this example React snippet:
```jsx
class Table extends React.Component {
render() {
return (
<table>
<tr>
<Columns />
</tr>
</table>
);
}
}
```
`<Columns />` would need to return multiple `<td>` elements in order for the rendered HTML to be valid. If a parent div was used inside the `render()` of `<Columns />`, then the resulting HTML will be invalid.
```jsx
class Columns extends React.Component {
render() {
return (
<div>
<td>Hello</td>
<td>World</td>
</div>
);
}
}
```
results in a `<Table />` output of:
```jsx
<table>
<tr>
<div>
<td>Hello</td>
<td>World</td>
</div>
</tr>
</table>
```
So, we introduce `Fragment`s.
## Usage
```jsx{4,7}
class Columns extends React.Component {
render() {
return (
<React.Fragment>
<td>Hello</td>
<td>World</td>
</React.Fragment>
);
}
}
```
which results in a correct `<Table />` output of:
```jsx
<table>
<tr>
<td>Hello</td>
<td>World</td>
</tr>
</table>
```
### Short Syntax
There is a new, shorter syntax you can use for declaring fragments. It looks like empty tags:
```jsx{4,7}
class Columns extends React.Component {
render() {
return (
<>
<td>Hello</td>
<td>World</td>
</>
);
}
}
```
You can use `<></>` the same way you'd use any other element except that it doesn't support keys or attributes.
Note that **[many tools don't support it yet](/blog/2017/11/28/react-v16.2.0-fragment-support.html#support-for-fragment-syntax)** so you might want to explicitly write `<React.Fragment>` until the tooling catches up.
### Keyed Fragments
Fragments declared with the explicit `<React.Fragment>` syntax may have keys. A use case for this is mapping a collection to an array of fragments -- for example, to create a description list:
```jsx
function Glossary(props) {
return (
<dl>
{props.items.map(item => (
// Without the `key`, React will fire a key warning
<React.Fragment key={item.id}>
<dt>{item.term}</dt>
<dd>{item.description}</dd>
</React.Fragment>
))}
</dl>
);
}
```
`key` is the only attribute that can be passed to `Fragment`. In the future, we may add support for additional attributes, such as event handlers.
### Live Demo
You can try out the new JSX fragment syntax with this [CodePen](https://codepen.io/reactjs/pen/VrEbjE?editors=1000).

12
content/docs/how-to-contribute.md

@ -82,10 +82,12 @@ The core team is monitoring for pull requests. We will review your pull request
2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
5. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`).
6. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
7. Run the [Flow](https://flowtype.org/) typechecks (`yarn flow`).
8. If you haven't already, complete the CLA.
5. Run `yarn test-prod` to test in the production environment. It supports the same options as `yarn test`.
6. If you need a debugger, run `yarn debug-test --watch TestName`, open `chrome://inspect`, and press "Inspect".
7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
9. Run the [Flow](https://flowtype.org/) typechecks (`yarn flow`).
10. If you haven't already, complete the CLA.
### Contributor License Agreement (CLA)
@ -109,6 +111,8 @@ Then, you can run several commands:
* `yarn test` runs the complete test suite.
* `yarn test --watch` runs an interactive test watcher.
* `yarn test <pattern>` runs tests with matching filenames.
* `yarn test-prod` runs tests in the production environment. It supports all the same options as `yarn test`.
* `yarn debug-test` is just like `yarn test` but with a debugger. Open `chrome://inspect` and press "Inspect".
* `yarn flow` runs the [Flow](https://flowtype.org/) typechecks.
* `yarn build` creates a `build` folder with all the packages.
* `yarn build core,dom --type=UMD` creates UMD builds of just React and ReactDOM.

2
content/docs/implementation-notes.md

@ -14,7 +14,7 @@ It is very technical and assumes a strong understanding of React public API as w
It also assumes an understanding of the [differences between React components, their instances, and elements](/blog/2015/12/18/react-components-elements-and-instances.html).
The stack reconciler is powering all the React production code today. It is located in [`src/renderers/shared/stack/reconciler`](https://github.com/facebook/react/tree/master/src/renderers/shared/stack) and is used by both React DOM and React Native.
The stack reconciler was used in React 15 and earlier. It is located at [src/renderers/shared/stack/reconciler](https://github.com/facebook/react/tree/15-stable/src/renderers/shared/stack/reconciler).
### Video: Building React from Scratch

12
content/docs/introducing-jsx.md

@ -18,6 +18,16 @@ It is called JSX, and it is a syntax extension to JavaScript. We recommend using
JSX produces React "elements". We will explore rendering them to the DOM in the [next section](/docs/rendering-elements.html). Below, you can find the basics of JSX necessary to get you started.
### Why JSX?
React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time, and how the data is prepared for display.
Instead of artificially separating *technologies* by putting markup and logic in separate files, React [separates *concerns*](https://en.wikipedia.org/wiki/Separation_of_concerns) with loosely coupled units called "components" that contain both. We will come back to components in a [further section](/docs/components-and-props.html), but if you're not yet comfortable putting markup in JS, [this talk](https://www.youtube.com/watch?v=x7cQ3mrcKaY) might convince you otherwise.
React [doesn't require](/docs/react-without-jsx.html) using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages.
With that out of the way, let's get started!
### Embedding Expressions in JSX
You can embed any [JavaScript expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions) in JSX by wrapping it in curly braces.
@ -52,7 +62,7 @@ We split JSX over multiple lines for readability. While it isn't required, when
### JSX is an Expression Too
After compilation, JSX expressions become regular JavaScript objects.
After compilation, JSX expressions become regular JavaScript function calls and evaluate to JavaScript objects.
This means that you can use JSX inside of `if` statements and `for` loops, assign it to variables, accept it as arguments, and return it from functions:

4
content/docs/lists-and-keys.md

@ -130,7 +130,9 @@ const todoItems = todos.map((todo, index) =>
);
```
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. If you choose not to assign a key to your list items then React will use indexes as keys. You may read an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children) if you're interested in more information.
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an [in-depth explanation on the negative impacts of using an index as a key](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). If you choose not to assign an explicit key to list items then React will default to using indexes as keys.
Here is an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children) if you're interested in learning more.
### Extracting Components with Keys

2
content/docs/nav.yml

@ -48,6 +48,8 @@
title: Reconciliation
- id: context
title: Context
- id: fragments
title: Fragments
- id: portals
title: Portals
- id: error-boundaries

9
content/docs/optimizing-performance.md

@ -164,7 +164,7 @@ In the **development** mode, you can visualize how components mount, update, and
To do this in Chrome:
1. Load your app with `?react_perf` in the query string (for example, `http://localhost:3000/?react_perf`).
1. Make sure you're running the application in the development mode.
2. Open the Chrome DevTools **[Performance](https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/timeline-tool)** tab and press **Record**.
@ -174,11 +174,18 @@ To do this in Chrome:
5. React events will be grouped under the **User Timing** label.
For a more detailed walkthrough, check out [this article by Ben Schwarz](https://building.calibreapp.com/debugging-react-performance-with-react-16-and-chrome-devtools-c90698a522ad).
Note that **the numbers are relative so components will render faster in production**. Still, this should help you realize when unrelated UI gets updated by mistake, and how deep and how often your UI updates occur.
Currently Chrome, Edge, and IE are the only browsers supporting this feature, but we use the standard [User Timing API](https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API) so we expect more browsers to add support for it.
## Virtualize Long Lists
If your application renders long lists of data (hundreds or thousands of rows), we recommended using a technique known as "windowing". This technique only renders a small subset of your rows at any given time, and can dramatically reduce the time it takes to re-render the components as well as the number of DOM nodes created.
[React Virtualized](https://bvaughn.github.io/react-virtualized/) is one popular windowing library. It provides several reusable components for displaying lists, grids, and tabular data. You can also create your own windowing component, like [Twitter did](https://medium.com/@paularmstrong/twitter-lite-and-high-performance-react-progressive-web-apps-at-scale-d28a00e780a3), if you want something more tailored to your application's specific use case.
## Avoid Reconciliation
React builds and maintains an internal representation of the rendered UI. It includes the React elements you return from your components. This representation lets React avoid creating DOM nodes and accessing existing ones beyond necessity, as that can be slower than operations on JavaScript objects. Sometimes it is referred to as a "virtual DOM", but it works the same way on React Native.

46
content/docs/reference-dom-elements.md

@ -60,6 +60,10 @@ The `selected` attribute is supported by `<option>` components. You can use it t
### style
>Note
>
>Some examples in the documentation use `style` for convenience, but **using the `style` attribute as the primary means of styling elements is generally not recommended.** In most cases, [`className`](#classname) should be used to reference classes defined in an external CSS stylesheet. `style` is most often used in React applications to add dynamically-computed styles at render time. See also [FAQ: Styling and CSS](/docs/faq-styling.html).
The `style` attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOM `style` JavaScript property, is more efficient, and prevents XSS security holes. For example:
```js
@ -88,16 +92,16 @@ function ComponentWithTransition() {
Style keys are camelCased in order to be consistent with accessing the properties on DOM nodes from JS (e.g. `node.style.backgroundImage`). Vendor prefixes [other than `ms`](http://www.andismith.com/blog/2012/02/modernizr-prefixed/) should begin with a capital letter. This is why `WebkitTransition` has an uppercase "W".
React will automatically append a "px" suffix to certain inline style properties. For example:
React will automatically append a "px" suffix to certain numeric inline style properties. If you want to use units other than "px", specify the value as a string with the desired unit. For example:
```js
// This:
// Result style: '10px'
<div style={{ height: 10 }}>
Hello World!
</div>;
</div>
// Becomes:
<div style="height: 10px;">
// Result style: '10%'
<div style={{ height: '10%' }}>
Hello World!
</div>
```
@ -108,6 +112,12 @@ Not all style properties are converted to pixel strings though. Certain ones rem
Normally, there is a warning when an element with children is also marked as `contentEditable`, because it won't work. This attribute suppresses that warning. Don't use this unless you are building a library like [Draft.js](https://facebook.github.io/draft-js/) that manages `contentEditable` manually.
### suppressHydrationWarning
If you use server-side React rendering, normally there is a warning when the server and the client render different content. However, in some rare cases, it is very hard or impossible to guarantee an exact match. For example, timestamps are expected to differ on the server and on the client.
If you set `suppressHydrationWarning` to `true`, React will not warn you about mismatches in the attributes and the content of that element. It only works one level deep, and is intended to be used as an escape hatch. Don't overuse it. You can read more about hydration in the [`ReactDOM.hydrate()` documentation](/docs/react-dom.html#hydrate).
### value
The `value` attribute is supported by `<input>` and `<textarea>` components. You can use it to set the value of the component. This is useful for building controlled components. `defaultValue` is the uncontrolled equivalent, which sets the value of the component when it is first mounted.
@ -129,19 +139,19 @@ These props work similarly to the corresponding HTML attributes, with the except
Some of the DOM attributes supported by React include:
```
accept acceptCharset accessKey action allowFullScreen allowTransparency alt
async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge
charSet checked cite classID className colSpan cols content contentEditable
contextMenu controls controlsList coords crossOrigin data dateTime default defer
dir disabled download draggable encType form formAction formEncType formMethod
formNoValidate formTarget frameBorder headers height hidden high href hrefLang
htmlFor httpEquiv icon id inputMode integrity is keyParams keyType kind label
lang list loop low manifest marginHeight marginWidth max maxLength media
mediaGroup method min minLength multiple muted name noValidate nonce open
optimum pattern placeholder poster preload profile radioGroup readOnly rel
required reversed role rowSpan rows sandbox scope scoped scrolling seamless
selected shape size sizes span spellCheck src srcDoc srcLang srcSet start step
style summary tabIndex target title type useMap value width wmode wrap
accept acceptCharset accessKey action allowFullScreen alt async autoComplete
autoFocus autoPlay capture cellPadding cellSpacing challenge charSet checked
cite classID className colSpan cols content contentEditable contextMenu controls
controlsList coords crossOrigin data dateTime default defer dir disabled
download draggable encType form formAction formEncType formMethod formNoValidate
formTarget frameBorder headers height hidden high href hrefLang htmlFor
httpEquiv icon id inputMode integrity is keyParams keyType kind label lang list
loop low manifest marginHeight marginWidth max maxLength media mediaGroup method
min minLength multiple muted name noValidate nonce open optimum pattern
placeholder poster preload profile radioGroup readOnly rel required reversed
role rowSpan rows sandbox scope scoped scrolling seamless selected shape size
sizes span spellCheck src srcDoc srcLang srcSet start step style summary
tabIndex target title type useMap value width wmode wrap
```
Similarly, all SVG attributes are fully supported:

2
content/docs/reference-glossary.md

@ -59,7 +59,7 @@ Typically, elements are not used directly, but get returned from components.
## [Components](/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:
React components are small, reusable 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) {

2
content/docs/reference-react-component.md

@ -188,7 +188,7 @@ componentDidMount()
This method is a good place to set up any subscriptions. If you do that, don't forget to unsubscribe in `componentWillUnmount()`.
Calling `setState()` in this method will trigger an extra rendering, but it is guaranteed to flush during the same tick. This guarantees that even though the `render()` will be called twice in this case, the user won't see the intermediate state. Use this pattern with caution because it often causes performance issues. It can, however, be necessary for cases like modals and tooltips when you need to measure a DOM node before rendering something that depends on its size or position.
Calling `setState()` in this method will trigger an extra rendering, but it will happen before the browser updates the screen. This guarantees that even though the `render()` will be called twice in this case, the user won't see the intermediate state. Use this pattern with caution because it often causes performance issues. It can, however, be necessary for cases like modals and tooltips when you need to measure a DOM node before rendering something that depends on its size or position.
* * *

6
content/docs/reference-react-dom.md

@ -20,7 +20,7 @@ The `react-dom` package provides DOM-specific methods that can be used at the to
### Browser Support
React supports all popular browsers, including Internet Explorer 9 and above.
React supports all popular browsers, including Internet Explorer 9 and above, although [some polyfills are required](/docs/javascript-environment-requirements.html) for older browsers.
> Note
>
@ -64,7 +64,9 @@ ReactDOM.hydrate(element, container[, callback])
Same as [`render()`](#render), but is used to hydrate a container whose HTML contents were rendered by [`ReactDOMServer`](/docs/react-dom-server.html). React will attempt to attach event listeners to the existing markup.
React expects that the rendered content is identical between the server and the client. It can patch up differences in text content (such as timestamps), but you should treat mismatches as bugs and fix them. In development mode, React warns about mismatches during hydration. There are no guarantees that attribute differences will be patched up in case of mismatches. This is important for performance reasons because in most apps, mismatches are rare, and so validating all markup would be prohibitively expensive.
React expects that the rendered content is identical between the server and the client. It can patch up differences in text content, but you should treat mismatches as bugs and fix them. In development mode, React warns about mismatches during hydration. There are no guarantees that attribute differences will be patched up in case of mismatches. This is important for performance reasons because in most apps, mismatches are rare, and so validating all markup would be prohibitively expensive.
If a single element's attribute or text content is unavoidably different between the server and the client (for example, a timestamp), you may silence the warning by adding `suppressHydrationWarning={true}` to the element. It only works one level deep, and is intended to be an escape hatch. Don't overuse it. Unless it's text content, React still won't attempt to patch it up, so it may remain inconsistent until future updates.
If you intentionally need to render something different on the server and the client, you can do a two-pass rendering. Components that render something different on the client can read a state variable like `this.state.isClient`, which you can set to `true` in `componentDidMount()`. This way the initial render pass will render the same content as the server, avoiding mismatches, but an additional pass will happen synchronously right after hydration. Note that this approach will make your components slower because they have to render twice, so use it with caution.

33
content/docs/reference-react.md

@ -37,12 +37,18 @@ See [Using React without JSX](/docs/react-without-jsx.html) for more information
### Transforming Elements
`React` also provides some other APIs:
`React` provides several APIs for manipulating elements:
- [`cloneElement()`](#cloneelement)
- [`isValidElement()`](#isvalidelement)
- [`React.Children`](#reactchildren)
### Fragments
`React` also provides a component for rendering a multiple elements without a wrapper.
- [`React.Fragment`](#reactfragment)
* * *
## Reference
@ -65,7 +71,7 @@ See the [React.Component API Reference](/docs/react-component.html) for a list o
### `React.PureComponent`
`React.PureComponent` is exactly like [`React.Component`](#reactcomponent), but implements [`shouldComponentUpdate()`](/docs/react-component.html#shouldcomponentupdate) with a shallow prop and state comparison.
`React.PureComponent` is similar to [`React.Component`](#reactcomponent). The difference between them is that [`React.Component`](#reactcomponent) doesn't implement [`shouldComponentUpdate()`](/docs/react-component.html#shouldcomponentupdate), but `React.PureComponent` implements it with a shallow prop and state comparison.
If your React component's `render()` function renders the same result given the same props and state, you can use `React.PureComponent` for a performance boost in some cases.
@ -87,7 +93,7 @@ React.createElement(
)
```
Create and return a new [React element](/docs/rendering-elements.html) of the given type. The type argument can be either a tag name string (such as `'div'` or `'span'`), or a [React component](/docs/components-and-props.html) type (a class or a function).
Create and return a new [React element](/docs/rendering-elements.html) of the given type. The type argument can be either a tag name string (such as `'div'` or `'span'`), a [React component](/docs/components-and-props.html) type (a class or a function), or a [React fragment](#reactfragment) type.
Code written with [JSX](/docs/introducing-jsx.html) will be converted to use `React.createElement()`. You will not typically invoke `React.createElement()` directly if you are using JSX. See [React Without JSX](/docs/react-without-jsx.html) to learn more.
@ -123,7 +129,7 @@ This API was introduced as a replacement of the deprecated `React.addons.cloneWi
React.createFactory(type)
```
Return a function that produces React elements of a given type. Like [`React.createElement()`](#createElement), the type argument can be either a tag name string (such as `'div'` or `'span'`), or a [React component](/docs/components-and-props.html) type (a class or a function).
Return a function that produces React elements of a given type. Like [`React.createElement()`](#createElement), the type argument can be either a tag name string (such as `'div'` or `'span'`), a [React component](/docs/components-and-props.html) type (a class or a function), or a [React fragment](#reactfragment) type.
This helper is considered legacy, and we encourage you to either use JSX or use `React.createElement()` directly instead.
@ -192,3 +198,22 @@ Returns the `children` opaque data structure as a flat array with keys assigned
> Note:
>
> `React.Children.toArray()` changes keys to preserve the semantics of nested arrays when flattening lists of children. That is, `toArray` prefixes each key in the returned array so that each element's key is scoped to the input array containing it.
* * *
### `React.Fragment`
The `React.Fragment` component lets you return multiple elements in a `render()` method without creating an additional DOM element:
```javascript
render() {
return (
<React.Fragment>
Some text.
<h2>A heading</h2>
</React.Fragment>
);
}
```
You can also use it with the shorthand `<></>` syntax. For more information, see [React v16.2.0: Improved Support for Fragments](/blog/2017/11/28/react-v16.2.0-fragment-support.html).

139
content/docs/static-type-checking.md

@ -146,9 +146,132 @@ Now you're all set! We recommend to check out the following resources to learn m
## TypeScript
[TypeScript](https://www.typescriptlang.org/) is a programming language developed by Microsoft. It is a typed superset of JavaScript, and includes its own compiler.
[TypeScript](https://www.typescriptlang.org/) is a programming language developed by Microsoft. It is a typed superset of JavaScript, and includes its own compiler. Being a typed language, Typescript can catch errors and bugs at build time, long before your app goes live. You can learn more about using TypeScript with React [here](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter).
You can learn more about using TypeScript with React [here](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter).
To use TypeScript, you need to:
* Add Typescript as a dependency to your project
* Configure the TypeScript compiler options
* Use the right file extensions
* Add definitions for libraries you use
Let's go over these in detail.
### Adding TypeScript to a Project
It all begins with running one command in your terminal.
If you use [Yarn](https://yarnpkg.com/), run:
```bash
yarn add --dev typescript
```
If you use [npm](https://www.npmjs.com/), run:
```bash
npm install --save-dev typescript
```
Congrats! You've installed the latest version of TypeScript into your project. Installing TypeScript gives us access to the `tsc` command. Before configuration, let's add `tsc` to the "scripts" section in our `package.json`:
```js{4}
{
// ...
"scripts": {
"build": "tsc",
// ...
},
// ...
}
```
### Configuring the TypeScript Compiler
The compiler is of no help to us until we tell it what to do. In TypeScript, these rules are defined in a special file called `tsconfig.json`. To generate this file run:
```bash
tsc --init
```
Looking at the now generated `tsconfig.json`, you can see that there are many options you can use to configure the compiler. For a detailed description of all the options, check [here](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
Of the many options, we'll look at `rootDir` and `outDir`. In its true fashion, the compiler will take in typescript files and generate javascript files. However we don't want to get confused with our source files and the generated output.
We'll address this in two steps:
* Firstly, let's arrange our project structure like this. We'll place all our source code in the `src` directory.
```
├── package.json
├── src
│ └── index.ts
└── tsconfig.json
```
* Next, we'll tell the compiler where our source code is and where the output should go.
```js{6,7}
// tsconfig.json
{
"compilerOptions": {
// ...
"rootDir": "src",
"outDir": "build"
// ...
},
}
```
Great! Now when we run our build script the compiler will output the generated javascript to the `build` folder. The [TypeScript React Starter](https://github.com/Microsoft/TypeScript-React-Starter/blob/master/tsconfig.json) provides a `tsconfig.json` with a good set of rules to get you started.
Generally, you don't want to keep the generated javascript in your source control, so be sure to add the build folder to your `.gitignore`.
### File extensions
In React, you most likely write your components in a `.js` file. In TypeScript we have 2 file extensions:
`.ts` is the default file extension while `.tsx` is a special extension used for files which contain `JSX`.
### Running TypeScript
If you followed the instructions above, you should be able to run TypeScript for the first time.
```bash
yarn build
```
If you use npm, run:
```bash
npm run build
```
If you see no output, it mean's that it completed successfully.
### Type Definitions
To be able to show errors and hints from other packages, the compiler relies on declaration files. A declaration file provides all the type information about a library. This enables us to use javascript libraries like those on npm in our project.
There are two main ways to get declarations for a library:
__Bundled__ - The library bundles it's own declaration file. This is great for us, since all we need to do is install the library, and we can use it right away. To check if a library has bundled types, look for an `index.d.ts` file in the project. Some libraries will have it specified in their `package.json` under the `typings` or `types` field.
__[DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped)__ - DefinitelyTyped is a huge repository of declarations for libraries that don't bundle a declaration file. The declarations are crowd-sourced and managed by Microsoft and open source contributors. React for example doesn't bundle it's own declaration file. Instead we can get it from DefinitelyTyped. To do so enter this command in your terminal.
```bash
# yarn
yarn add --dev @types/react
# npm
npm i --save-dev @types/react
```
__Local Declarations__
Sometimes the package that you want to use doesn't bundle declarations nor is it available on DefinitelyTyped. In that case, we can have a local declaration file. To do this, create a `declarations.d.ts` file in the root of your source directory. A simple declaration could look like this:
```typescript
declare module 'querystring' {
export function stringify(val: object): string
export function parse(val: string): object
}
```
### Using TypeScript with Create React App
@ -162,12 +285,24 @@ Note that it is a **third party** project, and is not a part of Create React App
You can also try [typescript-react-starter](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter).
You are now ready to code! We recommend to check out the following resources to learn more about Typescript:
* [TypeScript Documentation: Basic Types](https://www.typescriptlang.org/docs/handbook/basic-types.html)
* [TypeScript Documentation: Migrating from Javascript](http://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html)
* [TypeScript Documentation: React and Webpack](http://www.typescriptlang.org/docs/handbook/react-&-webpack.html)
## Reason
[Reason](https://reasonml.github.io/) is not a new language; it's a new syntax and toolchain powered by the battle-tested language, [OCaml](http://ocaml.org/). Reason gives OCaml a familiar syntax geared toward JavaScript programmers, and caters to the existing NPM/Yarn workflow folks already know.
Reason is developed at Facebook, and is used in some of its products like Messenger. It is still somewhat experimental but it has [dedicated React bindings](https://reasonml.github.io/reason-react/) maintained by Facebook and a [vibrant community](https://reasonml.github.io/community/).
## Kotlin
[Kotlin](https://kotlinlang.org/) is a statically typed language developed by JetBrains. Its target platforms include the JVM, Android, LLVM, and [JavaScript](https://kotlinlang.org/docs/reference/js-overview.html).
JetBrains develops and maintains several tools specifically for the React community: [React bindings](https://github.com/JetBrains/kotlin-wrappers) as well as [Create React Kotlin App](https://github.com/JetBrains/create-react-kotlin-app). The latter helps you start building React apps with Kotlin with no build configuration.
## Other Languages
Note there are other statically typed languages that compile to JavaScript and are thus React compatible. For example, [F#/Fable](http://fable.io) with [elmish-react](https://fable-elmish.github.io/react). Check out their respective sites for more information, and feel free to add more statically typed languages that work with React to this page!

1
content/docs/web-components.md

@ -58,3 +58,4 @@ customElements.define('x-search', XSearch);
>Note:
>
>This code **will not** work if you transform classes with Babel. See [this issue](https://github.com/w3c/webcomponents/issues/587) for the discussion.
>Include the [custom-elements-es5-adapter](https://github.com/webcomponents/webcomponentsjs#custom-elements-es5-adapterjs) before you load your web components to fix this issue.

BIN
content/images/blog/release-script-build-confirmation.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
content/images/blog/release-script-build-overview.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
content/images/blog/release-script-publish-confirmation.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

2
content/tutorial/tutorial.md

@ -377,7 +377,7 @@ The usual pattern here is pass down a function from Board to Square that gets ca
}
```
We split the returned element into multiple lines for readability, and added parens around it so that JavaScript doesn't insert a semicolon after `return` and break our code.
We split the returned element into multiple lines for readability, and added parentheses around it so that JavaScript doesn't insert a semicolon after `return` and break our code.
Now we're passing down two props from Board to Square: `value` and `onClick`. The latter is a function that Square can call. Let's make the following changes to Square:

2
examples/components-and-props/composing-components.js

@ -15,4 +15,4 @@ function App() {
ReactDOM.render(
<App />,
document.getElementById('root')
);
);

21
examples/components-and-props/extracting-components-continued.js

@ -4,9 +4,11 @@ function formatDate(date) {
function Avatar(props) {
return (
<img className="Avatar"
src={props.user.avatarUrl}
alt={props.user.name} />
<img
className="Avatar"
src={props.user.avatarUrl}
alt={props.user.name}
/>
);
}
@ -37,16 +39,19 @@ function Comment(props) {
const comment = {
date: new Date(),
text: 'I hope you enjoy learning React!',
text:
'I hope you enjoy learning React!',
author: {
name: 'Hello Kitty',
avatarUrl: 'http://placekitten.com/g/64/64'
}
avatarUrl:
'http://placekitten.com/g/64/64',
},
};
ReactDOM.render(
<Comment
date={comment.date}
text={comment.text}
author={comment.author} />,
author={comment.author}
/>,
document.getElementById('root')
);
);

21
examples/components-and-props/extracting-components.js

@ -6,9 +6,11 @@ function Comment(props) {
return (
<div className="Comment">
<div className="UserInfo">
<img className="Avatar"
src={props.author.avatarUrl}
alt={props.author.name} />
<img
className="Avatar"
src={props.author.avatarUrl}
alt={props.author.name}
/>
<div className="UserInfo-name">
{props.author.name}
</div>
@ -25,16 +27,19 @@ function Comment(props) {
const comment = {
date: new Date(),
text: 'I hope you enjoy learning React!',
text:
'I hope you enjoy learning React!',
author: {
name: 'Hello Kitty',
avatarUrl: 'http://placekitten.com/g/64/64'
}
avatarUrl:
'http://placekitten.com/g/64/64',
},
};
ReactDOM.render(
<Comment
date={comment.date}
text={comment.text}
author={comment.author} />,
author={comment.author}
/>,
document.getElementById('root')
);
);

2
examples/components-and-props/rendering-a-component.js

@ -6,4 +6,4 @@ const element = <Welcome name="Sara" />;
ReactDOM.render(
element,
document.getElementById('root')
);
);

6
examples/es5-syntax-example.js

@ -1,3 +1,5 @@
const element = <h1>Hello, world!</h1>;
const container = document.getElementById('root');
ReactDOM.render(element, container);
const container = document.getElementById(
'root'
);
ReactDOM.render(element, container);

8
examples/introducing-jsx.js

@ -1,5 +1,7 @@
function formatName(user) {
return user.firstName + ' ' + user.lastName;
return (
user.firstName + ' ' + user.lastName
);
}
const user = {
@ -8,9 +10,7 @@ const user = {
};
const element = (
<h1>
Hello, {formatName(user)}!
</h1>
<h1>Hello, {formatName(user)}!</h1>
);
ReactDOM.render(

2
examples/jsx-simple-example.js

@ -1,3 +1,3 @@
function hello() {
return <div>Hello world!</div>;
}
}

108
examples/reconciliation/index-used-as-key.js

@ -1,8 +1,16 @@
const ToDo = (props) => (
const ToDo = props => (
<tr>
<td><label>{props.id}</label></td>
<td><input/></td>
<td><label>{props.createdAt.toTimeString()}</label></td>
<td>
<label>{props.id}</label>
</td>
<td>
<input />
</td>
<td>
<label>
{props.createdAt.toTimeString()}
</label>
</td>
</tr>
);
@ -14,86 +22,114 @@ class ToDoList extends React.Component {
this.state = {
todoCounter: todoCounter,
list: [
{ id: todoCounter, createdAt: date },
]
}
{
id: todoCounter,
createdAt: date,
},
],
};
}
sortByEarliest() {
const sortedList = this.state.list.sort((a, b) => {
return a.createdAt - b.createdAt;
});
const sortedList = this.state.list.sort(
(a, b) => {
return (
a.createdAt - b.createdAt
);
}
);
this.setState({
list: [...sortedList]
})
list: [...sortedList],
});
}
sortByLatest() {
const sortedList = this.state.list.sort((a, b) => {
return b.createdAt - a.createdAt;
});
const sortedList = this.state.list.sort(
(a, b) => {
return (
b.createdAt - a.createdAt
);
}
);
this.setState({
list: [...sortedList]
})
list: [...sortedList],
});
}
addToEnd() {
const date = new Date();
const nextId = this.state.todoCounter + 1;
const nextId =
this.state.todoCounter + 1;
const newList = [
...this.state.list,
{ id: nextId, createdAt: date }
{id: nextId, createdAt: date},
];
this.setState({
list: newList,
todoCounter: nextId
todoCounter: nextId,
});
}
addToStart() {
const date = new Date();
const nextId = this.state.todoCounter + 1;
const nextId =
this.state.todoCounter + 1;
const newList = [
{ id: nextId, createdAt: date },
...this.state.list
{id: nextId, createdAt: date},
...this.state.list,
];
this.setState({
list: newList,
todoCounter: nextId
todoCounter: nextId,
});
}
render() {
return(
return (
<div>
<code>key=index</code><br/>
<button onClick={this.addToStart.bind(this)}>
<code>key=index</code>
<br />
<button
onClick={this.addToStart.bind(
this
)}>
Add New to Start
</button>
<button onClick={this.addToEnd.bind(this)}>
<button
onClick={this.addToEnd.bind(
this
)}>
Add New to End
</button>
<button onClick={this.sortByEarliest.bind(this)}>
<button
onClick={this.sortByEarliest.bind(
this
)}>
Sort by Earliest
</button>
<button onClick={this.sortByLatest.bind(this)}>
<button
onClick={this.sortByLatest.bind(
this
)}>
Sort by Latest
</button>
<table>
<tr>
<th>ID</th><th></th><th>created at</th>
<th>ID</th>
<th />
<th>created at</th>
</tr>
{
this.state.list.map((todo, index) => (
{this.state.list.map(
(todo, index) => (
<ToDo
key={index}
{...todo}
/>
))
}
)
)}
</table>
</div>
)
);
}
}

108
examples/reconciliation/no-index-used-as-key.js

@ -1,8 +1,16 @@
const ToDo = (props) => (
const ToDo = props => (
<tr>
<td><label>{props.id}</label></td>
<td><input/></td>
<td><label>{props.createdAt.toTimeString()}</label></td>
<td>
<label>{props.id}</label>
</td>
<td>
<input />
</td>
<td>
<label>
{props.createdAt.toTimeString()}
</label>
</td>
</tr>
);
@ -13,87 +21,115 @@ class ToDoList extends React.Component {
const toDoCounter = 1;
this.state = {
list: [
{ id: toDoCounter, createdAt: date },
{
id: toDoCounter,
createdAt: date,
},
],
toDoCounter: toDoCounter
}
toDoCounter: toDoCounter,
};
}
sortByEarliest() {
const sortedList = this.state.list.sort((a, b) => {
return a.createdAt - b.createdAt;
});
const sortedList = this.state.list.sort(
(a, b) => {
return (
a.createdAt - b.createdAt
);
}
);
this.setState({
list: [...sortedList]
})
list: [...sortedList],
});
}
sortByLatest() {
const sortedList = this.state.list.sort((a, b) => {
return b.createdAt - a.createdAt;
});
const sortedList = this.state.list.sort(
(a, b) => {
return (
b.createdAt - a.createdAt
);
}
);
this.setState({
list: [...sortedList]
})
list: [...sortedList],
});
}
addToEnd() {
const date = new Date();
const nextId = this.state.toDoCounter + 1;
const nextId =
this.state.toDoCounter + 1;
const newList = [
...this.state.list,
{ id: nextId, createdAt: date }
{id: nextId, createdAt: date},
];
this.setState({
list: newList,
toDoCounter: nextId
toDoCounter: nextId,
});
}
addToStart() {
const date = new Date();
const nextId = this.state.toDoCounter + 1;
const nextId =
this.state.toDoCounter + 1;
const newList = [
{ id: nextId, createdAt: date },
...this.state.list
{id: nextId, createdAt: date},
...this.state.list,
];
this.setState({
list: newList,
toDoCounter: nextId
toDoCounter: nextId,
});
}
render() {
return(
return (
<div>
<code>key=id</code><br/>
<button onClick={this.addToStart.bind(this)}>
<code>key=id</code>
<br />
<button
onClick={this.addToStart.bind(
this
)}>
Add New to Start
</button>
<button onClick={this.addToEnd.bind(this)}>
<button
onClick={this.addToEnd.bind(
this
)}>
Add New to End
</button>
<button onClick={this.sortByEarliest.bind(this)}>
<button
onClick={this.sortByEarliest.bind(
this
)}>
Sort by Earliest
</button>
<button onClick={this.sortByLatest.bind(this)}>
<button
onClick={this.sortByLatest.bind(
this
)}>
Sort by Latest
</button>
<table>
<tr>
<th>ID</th><th></th><th>created at</th>
<th>ID</th>
<th />
<th>created at</th>
</tr>
{
this.state.list.map((todo, index) => (
{this.state.list.map(
(todo, index) => (
<ToDo
key={todo.id}
{...todo}
/>
))
}
)
)}
</table>
</div>
)
);
}
}

6
examples/tutorial-expanded-version.js

@ -1,8 +1,10 @@
<div className="shopping-list">
<h1>Shopping List for {props.name}</h1>
<h1>
Shopping List for {props.name}
</h1>
<ul>
<li>Instagram</li>
<li>WhatsApp</li>
<li>Oculus</li>
</ul>
</div>
</div>;

14
flow-typed/glamor.js

@ -5,3 +5,17 @@ declare module 'glamor' {
},
};
}
declare module 'glamor/react' {
declare module.exports: {
createElement: any,
dom: any,
vars: any,
makeTheme: any,
propMerge: Function,
};
}
declare module 'glamor/reset' {
declare module.exports: any;
}

11
flow-typed/polyfills.js

@ -0,0 +1,11 @@
declare module 'array-from' {
declare module.exports: any;
}
declare module 'string.prototype.includes' {
declare module.exports: any;
}
declare module 'string.prototype.repeat' {
declare module.exports: any;
}

3
flow-typed/slugify.js

@ -0,0 +1,3 @@
declare module 'slugify' {
declare module.exports: any;
}

7
gatsby/onCreateNode.js

@ -45,13 +45,8 @@ module.exports = exports.onCreateNode = ({node, boundActionCreators, getNode}) =
}
if (!slug) {
// This will likely only happen for the partials in /content/home.
slug = `/${relativePath.replace('.md', '.html')}`;
// This should only happen for the partials in /content/home,
// But let's log it in case it happens for other files also.
console.warn(
`Warning: No slug found for "${relativePath}". Falling back to default "${slug}".`,
);
}
// Used to generate URL to view this content.

10
package.json

@ -25,7 +25,7 @@
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-relay": "^0.0.19",
"flow-bin": "^0.56.0",
"gatsby": "^1.9.9",
"gatsby": "^1.9.135",
"gatsby-link": "^1.6.9",
"gatsby-plugin-catch-links": "^1.0.9",
"gatsby-plugin-feed": "^1.3.9",
@ -79,10 +79,14 @@
"ci-check": "npm-run-all prettier:diff --parallel lint flow",
"dev": "gatsby develop -H 0.0.0.0",
"flow": "flow",
"format:source": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
"format:examples": "prettier --config .prettierrc.examples --write \"examples/**/*.js\"",
"lint": "eslint .",
"netlify": "yarn install && yarn build",
"prettier": "prettier --config .prettierrc --write \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
"prettier:diff": "prettier --config .prettierrc --list-different \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
"nit:source": "prettier --config .prettierrc --list-different \"{gatsby-*.js,{flow-typed,plugins,src}/**/*.js}\"",
"nit:examples": "prettier --config .prettierrc.examples --list-different \"examples/**/*.js\"",
"prettier": "yarn format:source && yarn format:examples",
"prettier:diff": "yarn nit:source && yarn nit:examples",
"reset": "rimraf ./.cache"
},
"devDependencies": {

2
src/components/ButtonLink/ButtonLink.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Link from 'gatsby-link';
import React from 'react';
import {colors, media} from 'theme';

2
src/components/ButtonLink/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import ButtonLink from './ButtonLink';
export default ButtonLink;

2
src/components/CodeEditor/CodeEditor.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import Remarkable from 'remarkable';

2
src/components/CodeEditor/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import CodeEditor from './CodeEditor';
export default CodeEditor;

2
src/components/Container/Container.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import React from 'react';
import {media} from 'theme';

2
src/components/Container/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Container from './Container';
export default Container;

2
src/components/ErrorDecoder/ErrorDecoder.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import React from 'react';
import type {Node} from 'react';

2
src/components/ErrorDecoder/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import ErrorDecoder from './ErrorDecoder';
export default ErrorDecoder;

19
src/components/Flex/Flex.js

@ -2,12 +2,25 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import {createElement} from 'glamor/react';
import type {Node} from 'react';
type Props = {
basis: string,
children: Node,
direction: string,
grow: number,
halign: string,
shrink: number,
type: string,
valign: string,
rest: Array<any>,
};
/**
* Convenience component for declaring a flexbox layout.
*/
@ -21,7 +34,7 @@ const Flex = ({
type = 'div',
valign = 'flex-start',
...rest
}) =>
}: Props) =>
createElement(
type,
{

2
src/components/Flex/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Flex from './Flex';
export default Flex;

2
src/components/Header/Header.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import React from 'react';
import {colors, fonts} from 'theme';

2
src/components/Header/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Header from './Header';
export default Header;

14
src/components/LayoutFooter/ExternalFooterLink.js

@ -2,15 +2,23 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import React from 'react';
import {colors} from 'theme';
import ExternalLinkSvg from 'templates/components/ExternalLinkSvg';
const ExternalFooterLink = ({children, href, target, rel}) => (
import type {Node} from 'react';
type Props = {
children: Node,
href: string,
target?: string,
rel?: string,
};
const ExternalFooterLink = ({children, href, target, rel}: Props) => (
<a
css={{
lineHeight: 2,

70
src/components/LayoutFooter/Footer.js

@ -2,10 +2,9 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import Container from 'components/Container';
import ExternalFooterLink from './ExternalFooterLink';
import FooterLink from './FooterLink';
@ -13,10 +12,11 @@ import FooterNav from './FooterNav';
import MetaTitle from 'templates/components/MetaTitle';
import React from 'react';
import {colors, media} from 'theme';
import {sectionListCommunity, sectionListDocs} from 'utils/sectionList';
import ossLogoPng from 'images/oss_logo.png';
const Footer = ({layoutHasSidebar = false}) => (
const Footer = ({layoutHasSidebar = false}: {layoutHasSidebar: boolean}) => (
<footer
css={{
backgroundColor: colors.darker,
@ -61,17 +61,27 @@ const Footer = ({layoutHasSidebar = false}) => (
}}>
<FooterNav layoutHasSidebar={layoutHasSidebar}>
<MetaTitle onDark={true}>Docs</MetaTitle>
<FooterLink to="/docs/hello-world.html">Quick Start</FooterLink>
<FooterLink to="/docs/thinking-in-react.html">
Thinking in React
</FooterLink>
<FooterLink to="/tutorial/tutorial.html">Tutorial</FooterLink>
<FooterLink to="/docs/jsx-in-depth.html">
Advanced Guides
</FooterLink>
{sectionListDocs.map(section => {
// Skip the Installation page for Quick Start
const defaultItem =
section.items[0].id === 'installation'
? section.items[1].id
: section.items[0].id;
return (
<FooterLink to={`/docs/${defaultItem}.html`}>
{section.title}
</FooterLink>
);
})}
</FooterNav>
<FooterNav layoutHasSidebar={layoutHasSidebar}>
<MetaTitle onDark={true}>Community</MetaTitle>
<MetaTitle onDark={true}>Channels</MetaTitle>
<ExternalFooterLink
href="https://github.com/facebook/react"
target="_blank"
rel="noopener">
GitHub
</ExternalFooterLink>
<ExternalFooterLink
href="http://stackoverflow.com/questions/tagged/reactjs"
target="_blank"
@ -104,42 +114,26 @@ const Footer = ({layoutHasSidebar = false}) => (
</ExternalFooterLink>
</FooterNav>
<FooterNav layoutHasSidebar={layoutHasSidebar}>
<MetaTitle onDark={true}>Resources</MetaTitle>
<FooterLink to="/community/conferences.html">
Conferences
</FooterLink>
<FooterLink to="/community/videos.html">Videos</FooterLink>
<ExternalFooterLink
href="https://github.com/facebook/react/wiki/Examples"
target="_blank"
rel="noopener">
Examples
</ExternalFooterLink>
<ExternalFooterLink
href="https://github.com/facebook/react/wiki/Complementary-Tools"
target="_blank"
rel="noopener">
Complementary Tools
</ExternalFooterLink>
<MetaTitle onDark={true}>Community</MetaTitle>
{sectionListCommunity.map(section => (
<FooterLink to={`/community/${section.items[0].id}.html`}>
{section.title}
</FooterLink>
))}
</FooterNav>
<FooterNav layoutHasSidebar={layoutHasSidebar}>
<MetaTitle onDark={true}>More</MetaTitle>
<FooterLink to="/tutorial/tutorial.html">Tutorial</FooterLink>
<FooterLink to="/blog/">Blog</FooterLink>
<ExternalFooterLink
href="https://github.com/facebook/react"
target="_blank"
rel="noopener">
GitHub
</ExternalFooterLink>
<FooterLink to="/acknowledgements.html">
Acknowledgements
</FooterLink>
<ExternalFooterLink
href="http://facebook.github.io/react-native/"
target="_blank"
rel="noopener">
React Native
</ExternalFooterLink>
<FooterLink to="/acknowledgements.html">
Acknowledgements
</FooterLink>
</FooterNav>
</div>
<section

13
src/components/LayoutFooter/FooterLink.js

@ -2,15 +2,22 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import Link from 'gatsby-link';
import React from 'react';
import {colors} from 'theme';
const FooterLink = ({children, target, to}) => (
import type {Node} from 'react';
type Props = {
children: Node,
target?: string,
to: string,
};
const FooterLink = ({children, target, to}: Props) => (
<Link
css={{
lineHeight: 2,

13
src/components/LayoutFooter/FooterNav.js

@ -2,14 +2,21 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import React from 'react';
import {media} from 'theme';
const FooterNav = ({children, title, layoutHasSidebar = false}) => (
import type {Node} from 'react';
type Props = {
children: Node,
title?: string,
layoutHasSidebar: boolean,
};
const FooterNav = ({children, title, layoutHasSidebar = false}: Props) => (
<div
css={{
display: 'flex',

2
src/components/LayoutFooter/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Footer from './Footer';
export default Footer;

7
src/components/LayoutHeader/DocSearch.js

@ -2,12 +2,17 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
import React, {Component} from 'react';
import {colors, media} from 'theme';
class DocSearch extends Component {
type State = {
enabled: boolean,
};
class DocSearch extends Component<{}, State> {
state = {
enabled: true,
};

5
src/components/LayoutHeader/Header.js

@ -2,10 +2,9 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import Container from 'components/Container';
import HeaderLink from './HeaderLink';
import Link from 'gatsby-link';
@ -17,7 +16,7 @@ import DocSearch from './DocSearch';
import logoSvg from 'icons/logo.svg';
const Header = ({location}) => (
const Header = ({location}: {location: Location}) => (
<header
css={{
backgroundColor: colors.darker,

11
src/components/LayoutHeader/HeaderLink.js

@ -2,15 +2,20 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import Link from 'gatsby-link';
import React from 'react';
import {colors, media} from 'theme';
const HeaderLink = ({isActive, title, to}) => (
type Props = {
isActive: boolean,
title: string,
to: string,
};
const HeaderLink = ({isActive, title, to}: Props) => (
<Link css={[style, isActive && activeStyle]} to={to}>
{title}
{isActive && <span css={activeAfterStyle} />}

2
src/components/LayoutHeader/SearchSvg.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import React from 'react';
const SearchSvg = () => (

2
src/components/LayoutHeader/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Header from './Header';
export default Header;

2
src/components/MarkdownHeader/MarkdownHeader.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import Flex from 'components/Flex';
import React from 'react';
import {colors, fonts, media} from 'theme';

2
src/components/MarkdownHeader/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import MarkdownHeader from './MarkdownHeader';
export default MarkdownHeader;

2
src/components/MarkdownPage/MarkdownPage.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import Container from 'components/Container';
import Flex from 'components/Flex';
import MarkdownHeader from 'components/MarkdownHeader';

2
src/components/MarkdownPage/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import MarkdownPage from './MarkdownPage';
export default MarkdownPage;

33
src/components/StickyResponsiveSidebar/StickyResponsiveSidebar.js

@ -2,34 +2,43 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import Container from 'components/Container';
import {Component, React} from 'react';
import React, {Component} from 'react';
import Sidebar from 'templates/components/Sidebar';
import {colors, media} from 'theme';
import ChevronSvg from 'templates/components/ChevronSvg';
class StickyResponsiveSidebar extends Component {
constructor(props, context) {
super(props, context);
type State = {
open: boolean,
};
type Props = {
enableScrollSync?: boolean,
createLink: Function, // TODO: Add better flow type once we Flow-type createLink
defaultActiveSection: string,
location: Location,
sectionList: Array<Object>, // TODO: Add better flow type once we have the Section component
};
class StickyResponsiveSidebar extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
open: false,
};
this._openNavMenu = this._openNavMenu.bind(this);
this._closeNavMenu = this._closeNavMenu.bind(this);
}
_openNavMenu() {
_openNavMenu = () => {
this.setState({open: !this.state.open});
}
};
_closeNavMenu() {
_closeNavMenu = () => {
this.setState({open: false});
}
};
render() {
const {open} = this.state;

2
src/components/StickyResponsiveSidebar/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import StickyResponsiveSidebar from './StickyResponsiveSidebar';
export default StickyResponsiveSidebar;

2
src/components/TitleAndMetaTags/TitleAndMetaTags.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import Helmet from 'react-helmet';
import React from 'react';

2
src/components/TitleAndMetaTags/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import TitleAndMetaTags from './TitleAndMetaTags';
export default TitleAndMetaTags;

2
src/html.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import React, {Component} from 'react';
let stylesStr;

9
src/icons/logo-white.svg

@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.5 -10.23174 23 20.46348">
<title>React Logo</title>
<circle cx="0" cy="0" r="2.05" fill="#fff"/>
<g stroke="#fff" stroke-width="1" fill="none">
<ellipse rx="11" ry="4.2"/>
<ellipse rx="11" ry="4.2" transform="rotate(60)"/>
<ellipse rx="11" ry="4.2" transform="rotate(120)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 360 B

10
src/icons/logo.svg

@ -1 +1,9 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 23 20.46348"><title>logo</title><path d="M18.9107,6.63257h0q-.36721-.126-.74042-.2333.06187-.25141.11441-.505c.56045-2.72064.194-4.91237-1.05739-5.63386-1.1998-.692-3.1621.02952-5.14394,1.75414q-.29293.2555-.57267.52554-.18727-.17951-.3811-.352C9.05257.3439,6.97066-.43316,5.72058.29046,4.52191.98436,4.16686,3.04489,4.67144,5.62322q.0753.383.17.76179c-.29458.08367-.57908.17284-.85127.26771C1.55514,7.50165,0,8.83225,0,10.21231c0,1.42546,1.66935,2.8552,4.20575,3.722q.3085.10494.62193.19442-.10179.408-.18068.82114c-.48106,2.53354-.10535,4.54521,1.09017,5.23484,1.23481.712,3.30725-.01985,5.32533-1.78387q.23926-.20917.47994-.44238.3029.29225.62173.56727c1.95477,1.68207,3.88531,2.36132,5.07982,1.66986,1.23369-.71416,1.63454-2.87525,1.114-5.50459q-.05955-.30124-.13792-.61481.21834-.06443.42772-.13355C21.28454,13.06915,23,11.65681,23,10.21232,23,8.82726,21.39478,7.48771,18.9107,6.63257ZM12.7284,2.75581C14.42646,1.278,16.01346.69457,16.73657,1.1116h0c.77014.44421,1.06971,2.2354.5858,4.58441q-.04758.22953-.10342.45724a23.53752,23.53752,0,0,0-3.07527-.48584A23.08128,23.08128,0,0,0,12.1995,3.24094Q12.45788,2.99184,12.7284,2.75581ZM6.79111,11.39124q.312.60265.65207,1.19013.34692.59911.7221,1.18117a20.92168,20.92168,0,0,1-2.11967-.3408C6.24867,12.766,6.49887,12.08443,6.79111,11.39124ZM6.79,9.08041c-.28613-.67863-.53093-1.34586-.73085-1.99019.65624-.14688,1.356-.26689,2.08516-.358q-.36611.571-.7051,1.15877Q7.10076,8.478,6.79,9.08041Zm.52228,1.15552q.45411-.94517.9783-1.8542v.0002q.52369-.90857,1.11521-1.77542c.684-.05171,1.38536-.07879,2.09432-.07879.71212,0,1.41437.02728,2.09819.0794q.58514.86487,1.10818,1.76941.52565.90635.99153,1.84545-.46083.94817-.98828,1.86173h-.0001q-.52261.90786-1.1034,1.7803c-.6824.04876-1.3876.0739-2.10623.0739-.71568,0-1.41193-.02229-2.08241-.06575q-.59555-.86995-1.12406-1.78305Q7.76789,11.18148,7.31227,10.23593Zm8.24853,2.33862q.347-.60182.667-1.21863h0a20.86671,20.86671,0,0,1,.77238,2.02327,20.85164,20.85164,0,0,1-2.14552.36573Q15.21935,13.16682,15.5608,12.57455Zm.65767-3.49343q-.31883-.605-.66163-1.19684h0q-.33727-.58258-.6994-1.15022c.7339.09263,1.437.21579,2.09717.36654A20.95909,20.95909,0,0,1,16.21847,9.08112ZM11.511,3.94359a21.01288,21.01288,0,0,1,1.3535,1.63393q-1.35843-.06419-2.7184-.00061C10.593,4.98765,11.0507,4.44022,11.511,3.94359ZM6.21284,1.14081c.76953-.44543,2.47095.18973,4.26428,1.782.11461.10179.22974.20836.34507.3186A23.54542,23.54542,0,0,0,8.86294,5.66608a24.008,24.008,0,0,0-3.06916.477q-.088-.35228-.15808-.70866v.0001C5.20339,3.22536,5.49044,1.559,6.21284,1.14081ZM5.09132,13.18233q-.286-.08187-.56778-.17773A8.32371,8.32371,0,0,1,1.841,11.57955a2.03072,2.03072,0,0,1-.85849-1.36724c0-.83742,1.24865-1.90571,3.33117-2.63178q.39208-.1361.79162-.24908a23.56455,23.56455,0,0,0,1.121,2.90478A23.92247,23.92247,0,0,0,5.09132,13.18233ZM10.41594,17.661a8.32161,8.32161,0,0,1-2.57467,1.61184h-.0001a2.03042,2.03042,0,0,1-1.61306.06067c-.72556-.41836-1.02706-2.03376-.61573-4.20035q.07337-.38407.168-.76363a23.10444,23.10444,0,0,0,3.0995.44869,23.90954,23.90954,0,0,0,1.97431,2.43929Q10.64,17.46459,10.41594,17.661Zm1.12223-1.11053c-.46569-.50253-.93015-1.05831-1.38383-1.65612q.66051.026,1.34566.02606.70326,0,1.38841-.03084A20.89425,20.89425,0,0,1,11.53817,16.55045Zm5.96651,1.367a2.03039,2.03039,0,0,1-.753,1.4278c-.72485.41958-2.275-.12581-3.94659-1.56431q-.2875-.24735-.57837-.52727a23.08914,23.08914,0,0,0,1.9279-2.448,22.93647,22.93647,0,0,0,3.11507-.48014q.07024.284.12449.55638h0A8.32,8.32,0,0,1,17.50468,17.91749Zm.83417-4.90739h-.0001c-.12571.04163-.25478.08184-.38629.12082a23.06121,23.06121,0,0,0-1.16468-2.91373,23.05112,23.05112,0,0,0,1.11938-2.87128c.23524.0682.46365.14.68372.21579,2.12842.73258,3.42665,1.81593,3.42665,2.65061C22.01753,11.10145,20.61538,12.25574,18.33885,13.0101Z" fill="#61dafb"/><path d="M11.5,8.1585a2.05386,2.05386,0,1,1-2.05381,2.05381A2.05381,2.05381,0,0,1,11.5,8.1585" fill="#61dafb"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.5 -10.23174 23 20.46348">
<title>React Logo</title>
<circle cx="0" cy="0" r="2.05" fill="#61dafb"/>
<g stroke="#61dafb" stroke-width="1" fill="none">
<ellipse rx="11" ry="4.2"/>
<ellipse rx="11" ry="4.2" transform="rotate(60)"/>
<ellipse rx="11" ry="4.2" transform="rotate(120)"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 366 B

10
src/layouts/index.js

@ -2,10 +2,9 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
// Polyfills for IE
import 'array-from';
import 'string.prototype.includes';
@ -23,7 +22,12 @@ import 'glamor/reset';
import 'css/reset.css';
import 'css/algolia.css';
class Template extends Component {
type Props = {
children: Function,
location: Location,
};
class Template extends Component<Props> {
render() {
const {children, location} = this.props;

2
src/pages/404.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import Container from 'components/Container';
import Header from 'components/Header';
import TitleAndMetaTags from 'components/TitleAndMetaTags';

2
src/pages/acknowledgements.html.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import Container from 'components/Container';
import Header from 'components/Header';
import TitleAndMetaTags from 'components/TitleAndMetaTags';

28
src/pages/blog/all.html.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import Link from 'gatsby-link';
import Container from 'components/Container';
import Header from 'components/Header';
@ -76,18 +74,20 @@ const AllBlogPosts = ({data}: Props) => (
</Link>
</h2>
<MetaTitle>{node.fields.date}</MetaTitle>
<div
css={{
color: colors.subtle,
marginTop: -5,
}}>
by{' '}
{toCommaSeparatedList(node.frontmatter.author, author => (
<span key={author.frontmatter.name}>
{author.frontmatter.name}
</span>
))}
</div>
{node.frontmatter.author ? (
<div
css={{
color: colors.subtle,
marginTop: -5,
}}>
by{' '}
{toCommaSeparatedList(node.frontmatter.author, author => (
<span key={author.frontmatter.name}>
{author.frontmatter.name}
</span>
))}
</div>
) : null}
</li>
))}
</ul>

10
src/pages/docs/error-decoder.html.js

@ -2,10 +2,9 @@
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
'use strict';
import Container from 'components/Container';
import ErrorDecoder from 'components/ErrorDecoder';
import Flex from 'components/Flex';
@ -19,7 +18,12 @@ import {createLinkDocs} from 'utils/createLink';
import findSectionForPath from 'utils/findSectionForPath';
import {sectionListDocs} from 'utils/sectionList';
const ErrorPage = ({data, location}) => (
type Props = {
data: Object,
location: Location,
};
const ErrorPage = ({data, location}: Props) => (
<Flex
direction="column"
grow="1"

147
src/pages/index.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import ButtonLink from 'components/ButtonLink';
import Container from 'components/Container';
import Flex from 'components/Flex';
@ -18,6 +16,7 @@ import createOgUrl from 'utils/createOgUrl';
import loadScript from 'utils/loadScript';
import {babelURL} from 'site-constants';
import ReactDOM from 'react-dom';
import logoWhiteSvg from 'icons/logo-white.svg';
class Home extends Component {
constructor(props, context) {
@ -99,72 +98,88 @@ class Home extends Component {
maxWidth: 1500, // Positioning of background logo
marginLeft: 'auto',
marginRight: 'auto',
backgroundImage: 'url(/large-logo.svg)',
backgroundRepeat: 'no-repeat',
backgroundPosition: '100% 100px',
backgroundSize: '50% auto',
position: 'relative',
'::before': {
content: ' ',
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
backgroundImage: `url(${logoWhiteSvg})`,
backgroundRepeat: 'no-repeat',
backgroundPosition: '100% 100px',
backgroundSize: '50% auto',
opacity: 0.05,
},
},
}}>
<Container>
<h1
css={{
color: colors.brand,
textAlign: 'center',
margin: 0,
fontSize: 45,
letterSpacing: '0.01em',
[media.size('xsmall')]: {
fontSize: 30,
},
[media.greaterThan('xlarge')]: {
fontSize: 60,
},
}}>
React
</h1>
<p
css={{
paddingTop: 15,
textAlign: 'center',
fontSize: 24,
letterSpacing: '0.01em',
fontWeight: 200,
[media.size('xsmall')]: {
fontSize: 16,
maxWidth: '12em',
marginLeft: 'auto',
marginRight: 'auto',
},
[media.greaterThan('xlarge')]: {
paddingTop: 20,
fontSize: 30,
},
}}>
A JavaScript library for building user interfaces
</p>
<Flex
valign="center"
css={{
paddingTop: 40,
[media.greaterThan('xlarge')]: {
paddingTop: 65,
},
}}>
<CtaItem>
<ButtonLink to="/docs/hello-world.html" type="primary">
Get Started
</ButtonLink>
</CtaItem>
<CtaItem>
<ButtonLink to="/tutorial/tutorial.html" type="secondary">
Take the Tutorial
</ButtonLink>
</CtaItem>
</Flex>
</Container>
<div
css={{
// Content should be above absolutely-positioned hero image
position: 'relative',
}}>
<Container>
<h1
css={{
color: colors.brand,
textAlign: 'center',
margin: 0,
fontSize: 45,
letterSpacing: '0.01em',
[media.size('xsmall')]: {
fontSize: 30,
},
[media.greaterThan('xlarge')]: {
fontSize: 60,
},
}}>
React
</h1>
<p
css={{
paddingTop: 15,
textAlign: 'center',
fontSize: 24,
letterSpacing: '0.01em',
fontWeight: 200,
[media.size('xsmall')]: {
fontSize: 16,
maxWidth: '12em',
marginLeft: 'auto',
marginRight: 'auto',
},
[media.greaterThan('xlarge')]: {
paddingTop: 20,
fontSize: 30,
},
}}>
A JavaScript library for building user interfaces
</p>
<Flex
valign="center"
css={{
paddingTop: 40,
[media.greaterThan('xlarge')]: {
paddingTop: 65,
},
}}>
<CtaItem>
<ButtonLink to="/docs/hello-world.html" type="primary">
Get Started
</ButtonLink>
</CtaItem>
<CtaItem>
<ButtonLink to="/tutorial/tutorial.html" type="secondary">
Take the Tutorial
</ButtonLink>
</CtaItem>
</Flex>
</Container>
</div>
</div>
</header>

2
src/pages/jsx-compiler.html.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import Container from 'components/Container';
import Header from 'components/Header';
import React from 'react';

2
src/prism-styles.js

@ -5,8 +5,6 @@
* @flow
*/
'use strict';
import {css} from 'glamor';
import {colors} from 'theme';

4
src/site-constants.js

@ -5,12 +5,10 @@
* @flow
*/
'use strict';
// NOTE: We can't just use `location.toString()` because when we are rendering
// the SSR part in node.js we won't have a proper location.
const urlRoot = 'https://reactjs.org';
const version = '16.1.1';
const version = '16.2.0';
const babelURL = '//unpkg.com/babel-standalone@6.26.0/babel.min.js';
export {urlRoot, version, babelURL};

2
src/templates/blog.js

@ -4,8 +4,6 @@
* @emails react-core
*/
'use strict';
import PropTypes from 'prop-types';
import React from 'react';
import MarkdownPage from 'components/MarkdownPage';

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save