Skip to content

Commit fb65da6

Browse files
authored
docs: class properties and object spread are no longer experimental (#4754)
Co-authored-by: Romain Bohdanowicz <[email protected]>
1 parent c3e09c5 commit fb65da6

File tree

6 files changed

+11
-15
lines changed

6 files changed

+11
-15
lines changed

content/docs/faq-functions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ class Foo extends Component {
3737
}
3838
```
3939

40-
#### Class Properties (Stage 3 Proposal) {#class-properties-stage-3-proposal}
40+
#### Class Properties (ES2022) {#class-properties-es2022}
4141

4242
```jsx
4343
class Foo extends Component {
44-
// Note: this syntax is experimental and not standardized yet.
4544
handleClick = () => {
4645
console.log('Click happened');
47-
}
46+
};
4847
render() {
4948
return <button onClick={this.handleClick}>Click Me</button>;
5049
}

content/docs/handling-events.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,14 @@ You have to be careful about the meaning of `this` in JSX callbacks. In JavaScri
9292

9393
This is not React-specific behavior; it is a part of [how functions work in JavaScript](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/). Generally, if you refer to a method without `()` after it, such as `onClick={this.handleClick}`, you should bind that method.
9494

95-
If calling `bind` annoys you, there are two ways you can get around this. If you are using the experimental [public class fields syntax](https://babeljs.io/docs/plugins/transform-class-properties/), you can use class fields to correctly bind callbacks:
95+
If calling `bind` annoys you, there are two ways you can get around this. You can use [public class fields syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields#public_instance_fields) to correctly bind callbacks:
9696

9797
```js{2-6}
9898
class LoggingButton extends React.Component {
9999
// This syntax ensures `this` is bound within handleClick.
100-
// Warning: this is *experimental* syntax.
101100
handleClick = () => {
102101
console.log('this is:', this);
103-
}
102+
};
104103
105104
render() {
106105
return (

content/docs/hooks-intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ We'll discuss this more in [Using the Effect Hook](/docs/hooks-effect.html#tip-u
8080

8181
### Classes confuse both people and machines {#classes-confuse-both-people-and-machines}
8282

83-
In addition to making code reuse and code organization more difficult, we've found that classes can be a large barrier to learning React. You have to understand how `this` works in JavaScript, which is very different from how it works in most languages. You have to remember to bind the event handlers. Without unstable [syntax proposals](https://babeljs.io/docs/en/babel-plugin-transform-class-properties/), the code is very verbose. People can understand props, state, and top-down data flow perfectly well but still struggle with classes. The distinction between function and class components in React and when to use each one leads to disagreements even between experienced React developers.
83+
In addition to making code reuse and code organization more difficult, we've found that classes can be a large barrier to learning React. You have to understand how `this` works in JavaScript, which is very different from how it works in most languages. You have to remember to bind the event handlers. Without [ES2022 public class fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields#public_instance_fields), the code is very verbose. People can understand props, state, and top-down data flow perfectly well but still struggle with classes. The distinction between function and class components in React and when to use each one leads to disagreements even between experienced React developers.
8484

8585
Additionally, React has been out for about five years, and we want to make sure it stays relevant in the next five years. As [Svelte](https://svelte.dev/), [Angular](https://angular.io/), [Glimmer](https://glimmerjs.com/), and others show, [ahead-of-time compilation](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) of components has a lot of future potential. Especially if it's not limited to templates. Recently, we've been experimenting with [component folding](https://github.com/facebook/react/issues/7323) using [Prepack](https://prepack.io/), and we've seen promising early results. However, we found that class components can encourage unintentional patterns that make these optimizations fall back to a slower path. Classes present issues for today's tools, too. For example, classes don't minify very well, and they make hot reloading flaky and unreliable. We want to present an API that makes it more likely for code to stay on the optimizable path.
8686

content/docs/react-without-es6.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var SayHello = createReactClass({
134134

135135
This means writing ES6 classes comes with a little more boilerplate code for event handlers, but the upside is slightly better performance in large applications.
136136

137-
If the boilerplate code is too unattractive to you, you may enable the **experimental** [Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/) syntax proposal with Babel:
137+
If the boilerplate code is too unattractive to you, you may use [ES2022 Class Properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields#public_instance_fields) syntax:
138138

139139

140140
```javascript
@@ -143,11 +143,11 @@ class SayHello extends React.Component {
143143
super(props);
144144
this.state = {message: 'Hello!'};
145145
}
146-
// WARNING: this syntax is experimental!
146+
147147
// Using an arrow here binds the method:
148148
handleClick = () => {
149149
alert(this.state.message);
150-
}
150+
};
151151

152152
render() {
153153
return (
@@ -159,9 +159,7 @@ class SayHello extends React.Component {
159159
}
160160
```
161161

162-
Please note that the syntax above is **experimental** and the syntax may change, or the proposal might not make it into the language.
163-
164-
If you'd rather play it safe, you have a few options:
162+
You also have a few other options:
165163

166164
* Bind methods in the constructor.
167165
* Use arrow functions, e.g. `onClick={(e) => this.handleClick(e)}`.

content/docs/typechecking-with-proptypes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const root = ReactDOM.createRoot(document.getElementById('example'));
177177
root.render(<Greeting />);
178178
```
179179

180-
If you are using a Babel transform like [plugin-proposal-class-properties](https://babeljs.io/docs/en/babel-plugin-proposal-class-properties/) (previously _plugin-transform-class-properties_), you can also declare `defaultProps` as static property within a React component class. This syntax has not yet been finalized though and will require a compilation step to work within a browser. For more information, see the [class fields proposal](https://github.com/tc39/proposal-class-fields).
180+
Since ES2022 you can also declare `defaultProps` as static property within a React component class. For more information, see the [class public static fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Public_class_fields#public_static_fields). This modern syntax will require a compilation step to work within older browsers.
181181

182182
```javascript
183183
class Greeting extends React.Component {

content/tutorial/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ var player = {score: 1, name: 'Jeff'};
542542
var newPlayer = Object.assign({}, player, {score: 2});
543543
// Now player is unchanged, but newPlayer is {score: 2, name: 'Jeff'}
544544

545-
// Or if you are using object spread syntax proposal, you can write:
545+
// Or if you are using object spread syntax, you can write:
546546
// var newPlayer = {...player, score: 2};
547547
```
548548

0 commit comments

Comments
 (0)