You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -82,9 +81,9 @@ var Counter = createReactClass({
82
81
});
83
82
```
84
83
85
-
## Autobinding
84
+
## 自動バインド
86
85
87
-
In React components declared as ES6 classes, methods follow the same semantics as regular ES6 classes. This means that they don't automatically bind `this`to the instance. You'll have to explicitly use `.bind(this)`in the constructor:
@@ -132,10 +131,9 @@ var SayHello = createReactClass({
132
131
});
133
132
```
134
133
135
-
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.
136
-
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:
>**We also found numerous issues in codebases using mixins, [and don't recommend using them in the new code](/blog/2016/07/13/mixins-considered-harmful.html).**
Sometimes very different components may share some common functionality. These are sometimes called [cross-cutting concerns](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass`lets you use a legacy `mixins`system for that.
One common use case is a component wanting to update itself on a time interval. It's easy to use `setInterval()`, but it's important to cancel your interval when you don't need it anymore to save memory. React provides [lifecycle methods](/docs/react-component.html#the-component-lifecycle) that let you know when a component is about to be created or destroyed. Let's create a simple mixin that uses these methods to provide an easy `setInterval()`function that will automatically get cleaned up when your component is destroyed.
If a component is using multiple mixins and several mixins define the same lifecycle method (i.e. several mixins want to do some cleanup when the component is destroyed), all of the lifecycle methods are guaranteed to be called. Methods defined on mixins run in the order mixins were listed, followed by a method call on the component.
0 commit comments