Go to file
Dan Abramov bd23aa2712 Dedupe warnings about refs on functional components (#8739)
* Verify that functional component ref warning is deduplicated

It's not a big problem for string refs because the ref stays the same and the warning code path runs once per mount.

However, it is super annoying for functional refs since they're often written as arrows, and thus the warning fires for every render.

Both tests are currently failing since we're mounting twice, so even the string ref case prints warnings twice.

* Extract the warning condition to the top level

We don't want to run getStackAddendumByID() unless we actually know we're going to print the warning.

This doesn't affect correctness. Just a performance fix.

* Deduplicate warnings about refs on functional components

This fixes the duplicate warnings and adds an additional test for corner cases.

Our goal is to print one warning per one offending call site, when possible.

We try to use the element source for deduplication first because it gives us the exact JSX call site location.

If the element source is not available, we try to use the owner name for deduplication.

If even owner name is unavailable, we try to use the functional component unique identifier for deduplication so that at least the warning is seen once per mounted component.
2017-01-10 09:54:48 -08:00
.github use npm-run-script in PULL_REQUEST_TEMPLATE (#7913) 2016-10-07 14:23:37 +01:00
docs Fix single vs plural (#8738) 2017-01-10 08:00:16 -08:00
eslint-rules Year-agnostic copyright message, like React Native uses, to prevent the need for yearly changes. 2015-12-29 20:20:32 +01:00
examples Move new example changes to fixtures folder 2017-01-06 17:09:39 -05:00
fixtures Updating paths in packaging fixtures README 2017-01-09 16:06:08 -06:00
flow Added new fiber-based renderer for native dubbed ReactNativeFiber 2016-12-14 18:39:22 -08:00
grunt Replace Starter Kit with doc link (#8682) 2017-01-04 09:39:01 -08:00
gulp/tasks #8021 (#8241) 2016-11-09 16:51:02 +00:00
mocks Year-agnostic copyright message, like React Native uses, to prevent the need for yearly changes. 2015-12-29 20:20:32 +01:00
packages Bump react-noop-renderer version to fix CI 2017-01-10 13:41:31 +00:00
scripts Dedupe warnings about refs on functional components (#8739) 2017-01-10 09:54:48 -08:00
src Dedupe warnings about refs on functional components (#8739) 2017-01-10 09:54:48 -08:00
.babelrc Add babel-plugin-transform-class-properties (#7322) 2016-07-20 17:39:10 -07:00
.editorconfig Add insert_final_newline to editorconfig 2015-09-03 13:43:42 -07:00
.eslintignore [rrm] Lint 2017-01-06 06:00:09 -08:00
.eslintrc.js Upgrade ESLint and dependencies, fix new lint errors, switch Travis to Yarn (#8309) 2016-11-17 22:16:44 +00:00
.flowconfig Update Flow to 0.37.0 (#8608) 2016-12-20 11:09:03 -08:00
.gitattributes .gitattributes to ensure LF line endings when we should 2014-01-17 16:25:53 -08:00
.gitignore Remove fixture react build files from git tracking 2017-01-06 16:27:59 -06:00
.mailmap Update authors for v15 2016-04-04 09:46:23 -07:00
.travis.yml Update Travis config for new token 2016-11-30 17:17:04 -08:00
AUTHORS Update authors for v15 2016-04-04 09:46:23 -07:00
CHANGELOG.md Add missing entry for #7750 to 15.4.2 changelog 2017-01-09 14:15:35 +00:00
CONTRIBUTING.md Move How to Contribute to documentation and update it (#7817) 2016-09-27 23:20:49 +01:00
Gruntfile.js Replace Starter Kit with doc link (#8682) 2017-01-04 09:39:01 -08:00
LICENSE Year-agnostic copyright message, like React Native uses, to prevent the need for yearly changes. 2015-12-29 20:20:32 +01:00
LICENSE-docs Update licenses for docs and examples 2014-10-22 12:35:08 -07:00
LICENSE-examples Update licenses for docs and examples 2014-10-22 12:35:08 -07:00
PATENTS Update Patent Grant 2015-04-10 12:15:29 -07:00
README.md Replace Starter Kit with doc link (#8682) 2017-01-04 09:39:01 -08:00
circle.yml Support parallelism on Circle (#8511) 2016-12-07 14:55:34 -08:00
gulpfile.js Renamed InitializeJavaScriptAppEngine to InitializeCore 2016-12-12 11:23:25 -08:00
package.json 16.0.0-alpha.0 2017-01-09 16:45:56 -08:00
yarn.lock Replace Starter Kit with doc link (#8682) 2017-01-04 09:39:01 -08:00

README.md

React · CircleCI Status Build Status Coverage Status npm version PRs Welcome

React is a JavaScript library for building user interfaces.

  • Declarative: React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable, simpler to understand, and easier to debug.
  • Component-Based: Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.
  • Learn Once, Write Anywhere: We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using React Native.

Learn how to use React in your own project.

Examples

We have several examples on the website. Here is the first one to get you started:

class HelloMessage extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

ReactDOM.render(
  <HelloMessage name="John" />,
  document.getElementById('container')
);

This example will render "Hello John" into a container on the page.

You'll notice that we used an HTML-like syntax; we call it JSX. JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML. We recommend using Babel with a React preset to convert JSX into native JavaScript for browsers to digest.

Installation

React is available as the react package on npm. It is also available on a CDN.

React is flexible and can be used in a variety of projects. You can create new apps with it, but you can also gradually introduce it into an existing codebase without doing a rewrite.

The recommended way to install React depends on your project. Here you can find short guides for the most common scenarios:

Contributing

The main purpose of this repository is to continue to evolve React core, making it faster and easier to use. Development of React happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React.

Good First Bug

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first bugs that contain bugs which are fairly easy to fix. This is a great place to get started.

License

React is BSD licensed. We also provide an additional patent grant.

React documentation is Creative Commons licensed.

Examples provided in this repository and in the documentation are separately licensed.

Troubleshooting

See the Troubleshooting Guide