Skip to content

Commit ac62474

Browse files
Merge pull request #86 from reactjs/sync-8f7ffa47
Sync with reactjs.org @ 8f7ffa4
2 parents 7294b88 + 513bd21 commit ac62474

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1705
-1011
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
Note to Hacktoberfest 🎃 participants:
12

3+
While we appreciate the enthusiasm, we are experiencing a high volume of drive-by pull requests (one-line changes, README tweaks, etc.). Please remember that hundreds of people are subscribed to this repo and will receive notifications for these PRs. Spam submissions will be closed and won't count towards your Hacktoberfest goals.
24

5+
Please search for issues tagged [`good first issue`][gfi] or [`hacktoberfest`][hacktoberfest] to find things to work on.
6+
7+
You can also search [all of GitHub][all].
8+
9+
[gfi]: https://github.com/reactjs/reactjs.org/issues?q=is%3Aissue+is%3Aopen+label%3A"good+first+issue"
10+
[hacktoberfest]: https://github.com/reactjs/reactjs.org/issues?q=is%3Aissue+is%3Aopen+label%3A"good+first+issue"
11+
[all]: https://github.com/search?q=is%3Aissue+hacktoberfest
312
<!--
413
514
Thank you for the PR! Contributors like you keep React awesome!

content/authors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ kmeht:
5252
LoukaN:
5353
name: Lou Husson
5454
url: https://twitter.com/loukan42
55+
lunaruan:
56+
name: Luna Ruan
57+
url: https://twitter.com/lunaruan
5558
matthewjohnston4:
5659
name: Matthew Johnston
5760
url: https://github.com/matthewathome

content/blog/2020-08-10-react-v17-rc.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,17 @@ useEffect(() => {
162162

163163
Most effects don't need to delay screen updates, so React runs them asynchronously soon after the update has been reflected on the screen. (For the rare cases where you need an effect to block paint, e.g. to measure and position a tooltip, prefer `useLayoutEffect`.)
164164

165-
However, the effect *cleanup* function, when it exists, used to run synchronously in React 16. We've found that, similar to `componentWillUnmount` being synchronous in classes, this is not ideal for larger apps because it slows down large screen transitions (e.g. switching tabs).
165+
However, when a component is unmounting, effect *cleanup* functions used to run synchronously (similar to `componentWillUnmount` being synchronous in classes). We've found that this is not ideal for larger apps because it slows down large screen transitions (e.g. switching tabs).
166166

167-
**In React 17, the effect cleanup function also runs asynchronously -- for example, if the component is unmounting, the cleanup will run _after_ the screen has been updated.**
167+
**In React 17, the effect cleanup function will always runs asynchronously -- for example, if the component is unmounting, the cleanup will run _after_ the screen has been updated.**
168168

169-
This mirrors how the effects themselves run more closely. In the rare cases where you might want to rely on the synchronous execution, you can switch to `useLayoutEffect` instead.
169+
This mirrors how the effects themselves run more closely. In the rare cases where you might want to rely on the synchronous execution, you can switch to `useLayoutEffect` instead.
170170

171171
>Note
172172
>
173173
>You might be wondering whether this means that you'll now be unable to fix warnings about `setState` on unmounted components. Don't worry -- React specifically checks for this case, and does *not* fire `setState` warnings in the short gap between unmounting and the cleanup. **So code cancelling requests or intervals can almost always stay the same.**
174174
175-
Additionally, React 17 executes the cleanup functions in the same order as the effects, according to their position in the tree. Previously, this order was occasionally different.
175+
Additionally, React 17 will always execute all effect cleanup functions (for all components) before it runs any new effects. React 16 only guaranteed this ordering for effects within a component.
176176

177177
#### Potential Issues {#potential-issues}
178178

@@ -272,20 +272,20 @@ We encourage you to try React 17.0 Release Candidate soon and [raise any issues]
272272
To install React 17 RC with npm, run:
273273

274274
```bash
275-
275+
276276
```
277277

278278
To install React 17 RC with Yarn, run:
279279

280280
```bash
281-
281+
282282
```
283283

284284
We also provide UMD builds of React via a CDN:
285285

286286
```html
287-
<script crossorigin src="https://unpkg.com/[email protected].1/umd/react.production.min.js"></script>
288-
<script crossorigin src="https://unpkg.com/[email protected].1/umd/react-dom.production.min.js"></script>
287+
<script crossorigin src="https://unpkg.com/[email protected].2/umd/react.production.min.js"></script>
288+
<script crossorigin src="https://unpkg.com/[email protected].2/umd/react-dom.production.min.js"></script>
289289
```
290290

291291
Refer to the documentation for [detailed installation instructions](/docs/installation.html).
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
---
2+
title: "Introducing the New JSX Transform"
3+
author: [lunaruan]
4+
---
5+
6+
Although React 17 [doesn't contain new features](/blog/2020/08/10/react-v17-rc.html), it will provide support for a new version of the JSX transform. In this post, we will describe what it is and how to try it.
7+
8+
## What's a JSX Transform? {#whats-a-jsx-transform}
9+
10+
Browsers don't understand JSX out of the box, so most React users rely on a compiler like Babel or TypeScript to **transform JSX code into regular JavaScript**. Many preconfigured toolkits like Create React App or Next.js also include a JSX transform under the hood.
11+
12+
Together with the React 17 release, we've wanted to make a few improvements to the JSX transform, but we didn't want to break existing setups. This is why we [worked with Babel](https://babeljs.io/blog/2020/03/16/7.9.0#a-new-jsx-transform-11154httpsgithubcombabelbabelpull11154) to **offer a new, rewritten version of the JSX transform** for people who would like to upgrade.
13+
14+
Upgrading to the new transform is completely optional, but it has a few benefits:
15+
16+
* With the new transform, you can **use JSX without importing React**.
17+
* Depending on your setup, its compiled output may **slightly improve the bundle size**.
18+
* It will enable future improvements that **reduce the number of concepts** you need to learn React.
19+
20+
**This upgrade will not change the JSX syntax and is not required.** The old JSX transform will keep working as usual, and there are no plans to remove the support for it.
21+
22+
23+
[React 17 RC](/blog/2020/08/10/react-v17-rc.html) already includes support for the new transform, so go give it a try! To make it easier to adopt, after React 17 is released, we also plan to backport its support to React 16.x, React 15.x, and React 0.14.x. You can find the upgrade instructions for different tools [below](#how-to-upgrade-to-the-new-jsx-transform).
24+
25+
Now let's take a closer look at the differences between the old and the new transform.
26+
27+
## What’s Different in the New Transform? {#whats-different-in-the-new-transform}
28+
29+
When you use JSX, the compiler transforms it into React function calls that the browser can understand. **The old JSX transform** turned JSX into `React.createElement(...)` calls.
30+
31+
For example, let's say your source code looks like this:
32+
33+
```js
34+
import React from 'react';
35+
36+
function App() {
37+
return <h1>Hello World</h1>;
38+
}
39+
```
40+
41+
Under the hood, the old JSX transform turns it into regular JavaScript:
42+
43+
```js
44+
import React from 'react';
45+
46+
function App() {
47+
return React.createElement('h1', null, 'Hello world');
48+
}
49+
```
50+
51+
>Note
52+
>
53+
>**Your source code doesn't need to change in any way.** We're describing how the JSX transform turns your JSX source code into the JavaScript code a browser can understand.
54+
55+
However, this is not perfect:
56+
57+
* Because JSX compiled into `React.createElement`, `React` needed to be in scope if you use JSX.
58+
* There are some [performance improvements and simplifications](https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#motivation) that `React.createElement` does not allow.
59+
60+
To solve these issues, React 17 introduces two new entry points to the React package that are intended to only be used by compilers like Babel and TypeScript. Instead of transforming JSX to `React.createElement`, **the new JSX transform** automatically imports special functions from those new entry points in the React package and calls them.
61+
62+
Let's say that your source code looks like this:
63+
64+
```js
65+
function App() {
66+
return <h1>Hello World</h1>;
67+
}
68+
```
69+
70+
This is what the new JSX transform compiles it to:
71+
72+
```js
73+
// Inserted by a compiler (don't import it yourself!)
74+
import {jsx as _jsx} from 'react/jsx-runtime';
75+
76+
function App() {
77+
return _jsx('h1', { children: 'Hello world' });
78+
}
79+
```
80+
81+
Note how our original code **did not need to import React** to use JSX anymore! (But we would still need to import React in order to use Hooks or other exports that React provides.)
82+
83+
**This change is fully compatible with all of the existing JSX code**, so you won't have to change your components. If you're curious, you can check out the [technical RFC](https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#detailed-design) for more details about how the new transform works.
84+
85+
> Note
86+
>
87+
> The functions inside `react/jsx-runtime` and `react/jsx-dev-runtime` must only be used by the compiler transform. If you need to manually create elements in your code, you should keep using `React.createElement`. It will continue to work and is not going away.
88+
89+
## How to Upgrade to the New JSX Transform {#how-to-upgrade-to-the-new-jsx-transform}
90+
91+
If you aren't ready to upgrade to the new JSX transform or if you are using JSX for another library, don't worry. The old transform will not be removed and will continue to be supported.
92+
93+
If you want to upgrade, you will need two things:
94+
95+
* **A version of React that supports the new transform** (currently, only [React 17 RC](/blog/2020/08/10/react-v17-rc.html) supports it, but after React 17.0 has been released, we plan to make additional compatible releases for 0.14.x, 15.x, and 16.x).
96+
* **A compatible compiler** (see instructions for different tools below).
97+
98+
Since the new JSX transform doesn't require React to be in scope, [we've also prepared an automated script](#removing-unused-react-imports) that will remove the unnecessary imports from your codebase.
99+
100+
### Create React App {#create-react-app}
101+
102+
Create React App support [has been added](https://github.com/facebook/create-react-app/pull/9645) and will be available in the [upcoming v4.0 release](https://gist.github.com/iansu/4fab7a9bfa5fa6ebc87a908c62f5340b) which is currently in beta testing.
103+
104+
### Next.js {#nextjs}
105+
106+
Next.js [v9.5.3](https://github.com/vercel/next.js/releases/tag/v9.5.3)+ uses the new transform for compatible React versions.
107+
108+
### Gatsby {#gatsby}
109+
110+
Gatsby [v2.24.5](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/CHANGELOG.md#22452-2020-08-28)+ uses the new transform for compatible React versions.
111+
112+
>Note
113+
>
114+
>If you get [this Gatsby error](https://github.com/gatsbyjs/gatsby/issues/26979) after upgrading to React `17.0.0-rc.2`, run `npm update` to fix it.
115+
116+
### Manual Babel Setup {#manual-babel-setup}
117+
118+
Support for the new JSX transform is available in Babel [v7.9.0](https://babeljs.io/blog/2020/03/16/7.9.0) and above.
119+
120+
First, you'll need to update to the latest Babel and plugin transform.
121+
122+
If you are using `@babel/plugin-transform-react-jsx`:
123+
124+
```bash
125+
# for npm users
126+
npm update @babel/core @babel/plugin-transform-react-jsx
127+
```
128+
129+
```bash
130+
# for yarn users
131+
yarn upgrade @babel/core @babel/plugin-transform-react-jsx
132+
```
133+
134+
If you are using `@babel/preset-react`:
135+
136+
```bash
137+
# for npm users
138+
npm update @babel/core @babel/preset-react
139+
```
140+
141+
```bash
142+
# for yarn users
143+
yarn upgrade @babel/core @babel/preset-react
144+
```
145+
146+
Currently, the old transform (`"runtime": "classic"`) is the default option. To enable the new transform, you can pass `{"runtime": "automatic"}` as an option to `@babel/plugin-transform-react-jsx` or `@babel/preset-react`:
147+
148+
```js
149+
// If you are using @babel/preset-react
150+
{
151+
"presets": [
152+
["@babel/preset-react", {
153+
"runtime": "automatic"
154+
}]
155+
]
156+
}
157+
```
158+
159+
```js
160+
// If you're using @babel/plugin-transform-react-jsx
161+
{
162+
"plugins": [
163+
["@babel/plugin-transform-react-jsx", {
164+
"runtime": "automatic"
165+
}]
166+
]
167+
}
168+
```
169+
170+
Starting from Babel 8, `"automatic"` will be the default runtime for both plugins. For more information, check out the Babel documentation for [@babel/plugin-transform-react-jsx](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx) and [@babel/preset-react](https://babeljs.io/docs/en/babel-preset-react).
171+
172+
> Note
173+
>
174+
> If you use JSX with a library other than React, you can use [the `importSource` option](https://babeljs.io/docs/en/babel-preset-react#importsource) to import from that library instead -- as long as it provides the necessary entry points. Alternatively, you can keep using the classic transform which will continue to be supported.
175+
176+
### ESLint {#eslint}
177+
178+
If you are using [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react), the `react/jsx-uses-react` and `react/react-in-jsx-scope` rules are no longer necessary and can be turned off or removed.
179+
180+
```js
181+
{
182+
// ...
183+
"rules": {
184+
// ...
185+
"react/jsx-uses-react": "off",
186+
"react/react-in-jsx-scope": "off"
187+
}
188+
}
189+
```
190+
191+
### TypeScript {#typescript}
192+
193+
TypeScript supports the JSX transform in [v4.1 beta](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#jsx-factories).
194+
195+
### Flow {#flow}
196+
197+
Flow supports the new JSX transform in [v0.126.0](https://github.com/facebook/flow/releases/tag/v0.126.0) and up.
198+
199+
## Removing Unused React Imports {#removing-unused-react-imports}
200+
201+
Because the new JSX transform will automatically import the necessary `react/jsx-runtime` functions, React will no longer need to be in scope when you use JSX. This might lead to unused React imports in your code. It doesn't hurt to keep them, but if you'd like to remove them, we recommend running a [“codemod”](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) script to remove them automatically:
202+
203+
```bash
204+
cd your_project
205+
npx react-codemod update-react-imports
206+
```
207+
208+
>Note
209+
>
210+
>If you're getting errors when running the codemod, try specifying a different JavaScript dialect when `npx react-codemod update-react-imports` asks you to choose one. In particular, at this moment the "JavaScript with Flow" setting supports newer syntax than the "JavaScript" setting even if you don't use Flow. [File an issue](https://github.com/reactjs/react-codemod/issues) if you run into problems.
211+
>
212+
>Keep in mind that the codemod output will not always match your project's coding style, so you might want to run [Prettier](https://prettier.io/) after the codemod finishes for consistent formatting.
213+
214+
215+
Running this codemod will:
216+
217+
* Remove all unused React imports as a result of upgrading to the new JSX transform.
218+
* Change all default React imports (i.e. `import React from "react"`) to destructured named imports (ex. `import { useState } from "react"`) which is the preferred style going into the future. This codemod **will not** affect the existing namespace imports (i.e. `import * as React from "react"`) which is also a valid style. The default imports will keep working in React 17, but in the longer term we encourage moving away from them.
219+
220+
For example,
221+
222+
```js
223+
import React from 'react';
224+
225+
function App() {
226+
return <h1>Hello World</h1>;
227+
}
228+
```
229+
230+
will be replaced with
231+
232+
```js
233+
function App() {
234+
return <h1>Hello World</h1>;
235+
}
236+
```
237+
238+
If you use some other import from React — for example, a Hook — then the codemod will convert it to a named import.
239+
240+
For example,
241+
242+
```js
243+
import React from 'react';
244+
245+
function App() {
246+
const [text, setText] = React.useState('Hello World');
247+
return <h1>{text}</h1>;
248+
}
249+
```
250+
251+
will be replaced with
252+
253+
```js
254+
import { useState } from 'react';
255+
256+
function App() {
257+
const [text, setText] = useState('Hello World');
258+
return <h1>{text}</h1>;
259+
}
260+
```
261+
262+
In addition to cleaning up unused imports, this will also help you prepare for a future major version of React (not React 17) which will support ES Modules and not have a default export.
263+
264+
## Thanks {#thanks}
265+
266+
We'd like to thank Babel, TypeScript, Create React App, Next.js, Gatsby, ESLint, and Flow maintainers for their help implementing and integrating the new JSX transform. We also want to thank the React community for their feedback and discussion on the related [technical RFC](https://github.com/reactjs/rfcs/pull/107).

content/community/conferences.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,31 @@ Do you know of a local React.js conference? Add it here! (Please keep the list c
1212

1313
## Upcoming Conferences {#upcoming-conferences}
1414

15-
### React Native EU 2020 {#react-native-eu-2020}
16-
September 3-4, 2020 - remote event
17-
18-
[Website](https://www.react-native.eu/) - [Twitter](https://twitter.com/react_native_eu) - [Facebook](https://www.facebook.com/reactnativeeu/) - [YouTube](https://www.youtube.com/watch?v=m0GfmlGFh3E&list=PLZ3MwD-soTTHy9_88QPLF8DEJkvoB5Tl-) - [Instagram](https://www.instagram.com/reactnative_eu/)
19-
20-
### render(ATL) 2020 {#render-atlanta-2020}
21-
September 13-15, 2020. Atlanta, GA, USA.
22-
23-
[Website](https://renderatl.com) - [Twitter](https://twitter.com/renderATL) - [Instagram](https://www.instagram.com/renderatl/) - [Facebook](https://www.facebook.com/renderatl/) - [LinkedIn](https://www.linkedin.com/company/renderatl)
24-
2515
### React Summit 2020 {#react-summit-2020}
26-
7am PST / 1pm EST / 4pm CEST October 15-16, 2020 - remote event
16+
October 15-16, 2020, 7am PST / 10am EST / 4pm CEST - remote event
2717

2818
[Website](https://reactsummit.com) - [Twitter](https://twitter.com/reactsummit) - [Facebook](https://www.facebook.com/reactamsterdam) - [Videos](https://youtube.com/c/ReactConferences)
2919

30-
### React Day Berlin 2020 {#react-day-berlin-2020}
31-
November 25-27, 2020 in Berlin, Germany
20+
### React Conf Brasil 2020 {#react-conf-brasil-2020}
21+
November 21, 2020 - remote event
3222

33-
[Website](https://reactday.berlin) - [Twitter](https://twitter.com/reactdayberlin) - [Facebook](https://www.facebook.com/reactdayberlin/) - [Videos](https://www.youtube.com/reactdayberlin)
23+
[Website](https://reactconf.com.br/) - [Twitter](https://twitter.com/reactconfbr) - [Slack](https://react.now.sh/)
3424

3525
### React Next 2020 {#react-next-2020}
36-
December 1, 2020. Tel Aviv, Israel.
26+
December 1-2, 2020 - remote event
3727

3828
[Website](https://react-next.com/) - [Twitter](https://twitter.com/reactnext) - [Facebook](https://www.facebook.com/ReactNext2016/)
3929

30+
### render(ATL) 2021 {#render-atlanta-2021}
31+
September 13-15, 2021. Atlanta, GA, USA
32+
33+
[Website](https://renderatl.com) - [Twitter](https://twitter.com/renderATL) - [Instagram](https://www.instagram.com/renderatl/) - [Facebook](https://www.facebook.com/renderatl/) - [LinkedIn](https://www.linkedin.com/company/renderatl)
34+
35+
### React India 2021 {#react-india-2021}
36+
November 12-13, 2021 in Mumbai, India
37+
38+
[Website](https://www.reactindia.io) - [Twitter](https://twitter.com/react_india) - [Facebook](https://www.facebook.com/ReactJSIndia/) - [LinkedIn](https://www.linkedin.com/showcase/14545585) - [YouTube](https://www.youtube.com/channel/UCaFbHCBkPvVv1bWs_jwYt3w/videos) [Website](https://www.reactindia.io) - [Twitter](https://twitter.com/react_india) - [Facebook](https://www.facebook.com/ReactJSIndia/) - [LinkedIn](https://www.linkedin.com/showcase/14545585) - [YouTube](https://www.youtube.com/channel/UCaFbHCBkPvVv1bWs_jwYt3w/videos)
39+
4040
## Past Conferences {#past-conferences}
4141

4242
### React.js Conf 2015 {#reactjs-conf-2015}
@@ -470,3 +470,8 @@ May 1, 2020. Streamed online on YouTube.
470470
May 14-15, 2020 in Paris, France
471471

472472
[Website](https://www.react-europe.org) - [Twitter](https://twitter.com/ReactEurope) - [Facebook](https://www.facebook.com/ReactEurope) - [Videos](https://www.youtube.com/c/ReacteuropeOrgConf)
473+
474+
### React Native EU 2020 {#react-native-eu-2020}
475+
September 3-4, 2020 - remote event
476+
477+
[Website](https://www.react-native.eu/) - [Twitter](https://twitter.com/react_native_eu) - [Facebook](https://www.facebook.com/reactnativeeu/) - [YouTube](https://www.youtube.com/watch?v=m0GfmlGFh3E&list=PLZ3MwD-soTTHy9_88QPLF8DEJkvoB5Tl-) - [Instagram](https://www.instagram.com/reactnative_eu/)

0 commit comments

Comments
 (0)