A declarative, efficient, and flexible JavaScript library for building user interfaces. reactjs.org
Go to file
Joseph Savona 4082b0e7d3
[compiler] Detect known incompatible libraries (#34027)
A few libraries are known to be incompatible with memoization, whether
manually via `useMemo()` or via React Compiler. This puts us in a tricky
situation. On the one hand, we understand that these libraries were
developed prior to our documenting the [Rules of
React](https://react.dev/reference/rules), and their designs were the
result of trying to deliver a great experience for their users and
balance multiple priorities around DX, performance, etc. At the same
time, using these libraries with memoization — and in particular with
automatic memoization via React Compiler — can break apps by causing the
components using these APIs not to update. Concretely, the APIs have in
common that they return a function which returns different values over
time, but where the function itself does not change. Memoizing the
result on the identity of the function will mean that the value never
changes. Developers reasonable interpret this as "React Compiler broke
my code".

Of course, the best solution is to work with developers of these
libraries to address the root cause, and we're doing that. We've
previously discussed this situation with both of the respective
libraries:
* React Hook Form:
https://github.com/react-hook-form/react-hook-form/issues/11910#issuecomment-2135608761
* TanStack Table:
https://github.com/facebook/react/issues/33057#issuecomment-2840600158
and https://github.com/TanStack/table/issues/5567

In the meantime we need to make sure that React Compiler can work out of
the box as much as possible. This means teaching it about popular
libraries that cannot be memoized. We also can't silently skip
compilation, as this confuses users, so we need these error messages to
be visible to users. To that end, this PR adds:

* A flag to mark functions/hooks as incompatible
* Validation against use of such functions
* A default type provider to provide declarations for two
known-incompatible libraries

Note that Mobx is also incompatible, but the `observable()` function is
called outside of the component itself, so the compiler cannot currently
detect it. We may add validation for such APIs in the future.

Again, we really empathize with the developers of these libraries. We've
tried to word the error message non-judgementally, because we get that
it's hard! We're open to feedback about the error message, please let us
know.
2025-08-28 16:21:15 -07:00
.codesandbox Update Code Sandbox CI to Node 20 to Match .nvmrc (#34329) 2025-08-28 18:33:12 -04:00
.github [ci] Cache playwright in run_devtools_e2e_tests (#34320) 2025-08-27 14:37:18 -04:00
compiler [compiler] Detect known incompatible libraries (#34027) 2025-08-28 16:21:15 -07:00
fixtures Add scrollIntoView to fragment instances (#32814) 2025-08-27 18:05:57 -04:00
flow-typed Update Flow to 0.265 (#34270) 2025-08-22 15:22:22 -04:00
packages [eprh] Update installation instructions in readme (#34331) 2025-08-28 18:27:49 -04:00
scripts Add scrollIntoView to fragment instances (#32814) 2025-08-27 18:05:57 -04:00
.editorconfig Remove trim_trailing_whitespace from editorconfig (#31413) 2024-11-04 15:30:02 -05:00
.eslintignore Update Flow to 0.263 (#34269) 2025-08-22 12:10:13 -04:00
.eslintrc.js Update Flow to 0.279 (#34277) 2025-08-25 11:02:56 -04:00
.git-blame-ignore-revs Add run prettier commit to .git-blame-ignore-revs 2024-07-18 17:42:45 -04:00
.gitattributes .gitattributes to ensure LF line endings when we should 2014-01-17 16:25:53 -08:00
.gitignore [forgive] Init (#31918) 2025-02-25 12:19:11 -05:00
.mailmap updates mailmap entries (#19824) 2020-09-12 13:05:52 -04:00
.nvmrc Upgrade node.js to 20 LTS (#32855) 2025-04-14 12:52:02 -04:00
.prettierignore [prettier] Ignore compiler/target (#31168) 2024-10-10 10:53:27 -04:00
.prettierrc.js [scripts] Switch back to flow parser for prettier (#33414) 2025-06-03 00:00:28 -04:00
.watchmanconfig .watchmanconfig must be valid json (#16118) 2019-07-11 19:01:02 -07:00
babel.config-react-compiler.js feat(eslint-plugin-react-hooks): merge rule from eslint-plugin-react-compiler into react-hooks plugin (#32416) 2025-03-12 21:43:06 -04:00
babel.config-ts.js [compiler] Aggregate error reporting, separate eslint rules (#34176) 2025-08-21 14:53:34 -07:00
babel.config.js Partially revert #32588 (#32621) 2025-03-15 15:21:57 -04:00
CHANGELOG.md Clean up 19.1.1 changelog (#34023) 2025-07-28 17:32:23 +01:00
CODE_OF_CONDUCT.md revert last grammatical edit (#25067) 2022-08-10 20:14:31 +01:00
CONTRIBUTING.md Fix: Updated link in CONTRIBUTING (#25381) 2022-10-03 10:29:57 -04:00
dangerfile.js Fix typo in dangerfile.js which results in an unreachable code path… (#32277) 2025-01-31 01:44:02 -05:00
flow-typed.config.json Update Flow to 0.263 (#34269) 2025-08-22 12:10:13 -04:00
LICENSE [Codemod] Update copyright header to Meta (#25315) 2022-10-18 11:19:24 -04:00
MAINTAINERS Update MAINTAINERS (#32238) 2025-01-27 13:40:45 -06:00
package.json Update Flow to 0.279 (#34277) 2025-08-25 11:02:56 -04:00
react.code-workspace created a vscode workspace file for the repo (#29830) 2024-06-13 16:23:42 +01:00
ReactVersions.js [eprh] Bump stable version (#32978) 2025-04-21 14:36:13 -04:00
README.md [ez] Remove circleci badge from readme 2024-07-29 13:26:14 -04:00
SECURITY.md Create SECURITY.md (#15784) 2020-01-09 14:07:41 -08:00
yarn.lock Update Flow to 0.279 (#34277) 2025-08-25 11:02:56 -04:00

React · GitHub license npm version (Runtime) Build and Test (Compiler) TypeScript 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 the 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 project.

Installation

React has been designed for gradual adoption from the start, and you can use as little or as much React as you need:

Documentation

You can find the React documentation on the website.

Check out the Getting Started page for a quick overview.

The documentation is divided into several sections:

You can improve it by sending pull requests to this repository.

Examples

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

import { createRoot } from 'react-dom/client';

function HelloMessage({ name }) {
  return <div>Hello {name}</div>;
}

const root = createRoot(document.getElementById('container'));
root.render(<HelloMessage name="Taylor" />);

This example will render "Hello Taylor" 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.

Contributing

The main purpose of this repository is to continue evolving 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 Issues

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started.

License

React is MIT licensed.