A framework for building native macOS apps with React.
Перейти к файлу
Nick Gerleman a53512fda4 VirtualizedList up-to-date state: Thread props to _createViewToken()
Summary:
This diff is part of an overall stack, meant to fix incorrect usage of `setState()` in `VirtualizedList`, which triggers new invariant checks added in `VirtualizedList_EXPERIMENTAL`. See the stack summary below for more information on the broader change.

## Diff Summary

`_createViewToken()` is called during state changes. Use explicit props passed in.

## Stack Summary
`VirtualizedList`'s component state is a set of cells to render. This state is set via the `setState()` class component API. The main "tick" function `VirtualizedList._updateCellsToRender()` calculates this new state using a combination of the current component state, and instance-local state like maps, measurement caches, etc.

From: https://reactjs.org/docs/state-and-lifecycle.html#state-updates-may-be-asynchronous
 ---
> React may batch multiple setState() calls into a single update for performance. Because this.props and this.state may be updated asynchronously, you should not rely on their values for calculating the next state. For example, this code may fail to update the counter:

```
// Wrong
this.setState({
  counter: this.state.counter + this.props.increment,
});
```
> To fix it, use a second form of setState() that accepts a function rather than an object. That function will receive the previous state as the first argument, and the props at the time the update is applied as the second argument:
```
// Correct
this.setState((state, props) => ({
  counter: state.counter + props.increment
}));
```
 ---
`_updateCellsToRender()` transitively calls many functions which will read directly from `this.props` or `this.state` instead of the value passed by the state updater. This intermittently fires invariant violations, when there is a mismatch.

This diff migrates all usages of `props` and `state` during state update to the values provied in `setState()`. To prevent future mismatch, and to provide better clarity on when it is safe to use `this.props`, `this.state`, I overrode `setState` to fire an invariant violation if it is accessed when it is unsafe to:

{F756963772}

Changelog:
[Internal][Fixed] - Thread props to _createViewToken()

Reviewed By: genkikondo

Differential Revision: D38294339

fbshipit-source-id: dc215e267f126a3789742c14c35479f509822710
2022-08-02 01:30:21 -07:00
.bundle Introduce Gemfile, ruby-version (#32303) 2021-10-01 21:22:26 -07:00
.circleci Reduce flakiness of CI (#34235) 2022-07-22 05:56:02 -07:00
.github (PULL_REQUEST_TEMPLATE) update link to changelog documentation (#34206) 2022-07-19 05:47:17 -07:00
IntegrationTests Rename js_glob as js_library_glob 2022-07-12 05:20:36 -07:00
Libraries VirtualizedList up-to-date state: Thread props to _createViewToken() 2022-08-02 01:30:21 -07:00
React Add isPrimary property implementation to the PointerEvent object 2022-07-26 11:41:48 -07:00
ReactAndroid Disable calculation of TransformedFrames in Layoutable ShadowNodex 2022-07-29 17:32:35 -07:00
ReactCommon Revert D38280674: Multisect successfully blamed D38280674 for test or build failures 2022-08-02 00:11:58 -07:00
bots Run Danger on all the PRs and use fail or warning where is needed (#33872) 2022-05-23 01:12:25 -07:00
docs Generate doc info for RN components 2019-09-19 18:36:25 -07:00
flow Migrates off getInstrumentedStats' deprecated fields 2022-07-06 20:00:15 -07:00
flow-typed/npm RN: Remove DeprecatedPropTypes 2022-01-20 18:17:03 -08:00
gradle Bump Gradle to 7.5.0 (#34310) 2022-08-01 06:31:18 -07:00
jest (jest/setup) remove removeEventListener from AccessibilityInfo and Linking mocks (#34260) 2022-07-27 04:33:02 -07:00
keystores
local-cli Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
packages Update ktfmt component on FBS:master 2022-08-02 00:25:12 -07:00
repo-config Upgrade Metro dependencies to 0.72.0 2022-07-29 04:11:53 -07:00
scripts Fix test-manual-e2e on Android/Hermes for New App Template (#34294) 2022-07-28 06:23:11 -07:00
sdks/hermes-engine Simplify logic to choose if we need to build hermes from source or not. (#34232) 2022-07-22 02:13:47 -07:00
template Bump Gradle to 7.5.0 (#34310) 2022-08-01 06:31:18 -07:00
third-party-podspecs bump RTC-Folly to 2021.07.22 (#33841) 2022-06-21 12:36:43 -07:00
tools/build_defs Rename js_glob as js_library_glob 2022-07-12 05:20:36 -07:00
.buckconfig Download kotlin compiler JARs for Buck instead of checking them in (#33209) 2022-03-02 13:04:49 -08:00
.buckjavaargs
.clang-format Moving ObjC specific clang-format rules to the common config 2019-02-11 13:07:09 -08:00
.editorconfig Revert removal of CRLF from Windows bat files (#31398) 2021-09-09 22:44:32 -07:00
.eslintignore Lint: fix few "no-unused-var" warnings for imports (#30157) 2020-10-26 17:19:14 -07:00
.eslintrc.js update to ESLint v8 2022-07-16 01:41:27 -07:00
.flowconfig Upgrade to Flow 0.183.1 2022-07-28 18:21:07 -07:00
.flowconfig.android Upgrade to Flow 0.183.1 2022-07-28 18:21:07 -07:00
.gitignore iOS: Use pre-built hermesc if available (#33827) 2022-05-13 14:43:14 -07:00
.node-version Added files for node version in reactive native project (#34171) 2022-07-11 06:20:58 -07:00
.prettierrc JS: Upgrade to Prettier v2.4.1 [1/n] 2021-11-02 22:14:16 -07:00
.ruby-version Bump ruby to 2.7.5 (#33485) 2022-04-12 07:59:52 -07:00
BUCK Apply lint updates from buildifier in xplat 2022-07-24 13:46:21 -07:00
CHANGELOG.md add 0.69.3 changelog (#34270) 2022-07-25 13:19:01 -07:00
CODE_OF_CONDUCT.md docs: add new version convenant contribuitor guide link (#32107) 2021-08-30 10:18:11 -07:00
CONTRIBUTING.md Update CONTRIBUTING.md, replace wiki links (#34035) 2022-06-21 19:30:23 -07:00
ECOSYSTEM.md ECOSYSTEM.md: update Partner entries (#34006) 2022-06-13 17:18:50 -07:00
Gemfile Bump ruby to 2.7.5 (#33485) 2022-04-12 07:59:52 -07:00
Gemfile.lock Bump ruby to 2.7.5 (#33485) 2022-04-12 07:59:52 -07:00
LICENSE Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
LICENSE-docs
README.md docs(readme): fix minimum iOS version in requirements section (#34134) 2022-07-06 12:16:31 -07:00
React-Core.podspec Fix hermes executor not available when use_frameworks is enabled (#34222) 2022-07-27 07:12:16 -07:00
React.podspec bump iOS and tvOS from 11.0 to 12.4 in cocoapods 2022-03-16 21:08:01 -07:00
build.gradle.kts Bump AGP from 7.2.0 to 7.2.1 (#34166) 2022-07-12 03:57:14 -07:00
cli.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
gradle.properties Do not specify a Kotlin version in the RN rootProject (#33589) 2022-04-08 03:44:56 -07:00
gradlew bump gradle to 7.3 (#32588) 2021-11-15 06:47:39 -08:00
gradlew.bat Re-sync with internal repository (#32212) 2021-09-15 10:45:06 +01:00
index.js Remove MaskedViewIOS from react-native-github 2022-07-22 17:07:26 -07:00
interface.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
jest-preset.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
jest.config.js Stop publishing jest/preprocessor.js to npm 2022-05-06 04:43:09 -07:00
metro.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
package.json chore: upgrade RN CLI to v9.0.0-alpha.9 (#34322) 2022-08-01 12:37:09 -07:00
react-native.config.js Upgrade RN CLI to v8 alpha (#33610) 2022-04-12 04:17:20 -07:00
react.gradle Update the hermesc output to be inside the $buildDir 2022-04-27 09:41:11 -07:00
rn-get-polyfills.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
runXcodeTests.sh Use realpath instead of readlink 2022-02-22 02:23:02 -08:00
settings.gradle.kts Format .kts files with ktfmt 2022-06-09 02:50:45 -07:00
template.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
yarn.lock chore: upgrade RN CLI to v9.0.0-alpha.9 (#34322) 2022-08-01 12:37:09 -07:00

README.md

React Native

Learn once, write anywhere:
Build mobile apps with React.

React Native is released under the MIT license. Current CircleCI build status. Current npm package version. PRs welcome! Follow @reactnative

Getting Started · Learn the Basics · Showcase · Contribute · Community · Support

React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.

  • Declarative. React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
  • Component-Based. Build encapsulated components that manage their state, then compose them to make complex UIs.
  • Developer Velocity. See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
  • Portability. Reuse code across iOS, Android, and other platforms.

React Native is developed and supported by many companies and individual core contributors. Find out more in our ecosystem overview.

Contents

📋 Requirements

React Native apps may target iOS 12.4 and Android 5.0 (API 21) or newer. You may use Windows, macOS, or Linux as your development operating system, though building and running iOS apps is limited to macOS. Tools like Expo can be used to work around this.

🎉 Building your first React Native app

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

📖 Documentation

The full documentation for React Native can be found on our website.

The React Native documentation discusses components, APIs, and topics that are specific to React Native. For further documentation on the React API that is shared between React Native and React DOM, refer to the React documentation.

The source for the React Native documentation and website is hosted on a separate repo, @facebook/react-native-website.

🚀 Upgrading

Upgrading to new versions of React Native may give you access to more APIs, views, developer tools, and other goodies. See the Upgrading Guide for instructions.

React Native releases are discussed in this discussion repo.

👏 How to Contribute

The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements. Read below to learn how you can take part in improving React Native.

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

Open Source Roadmap

You can learn more about our vision for React Native in the Roadmap.

Good First Issues

We have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

Discussions

Larger discussions and proposals are discussed in @react-native-community/discussions-and-proposals.

📄 License

React Native is MIT licensed, as found in the LICENSE file.

React Native documentation is Creative Commons licensed, as found in the LICENSE-docs file.