[DOC] add hooks explanation, and testing/debug page

closes #372
closes #419
This commit is contained in:
Géry Debongnie
2019-11-22 09:40:51 +01:00
committed by aab-odoo
parent ff76747a05
commit 48744cfa87
7 changed files with 232 additions and 11 deletions
+9 -3
View File
@@ -152,9 +152,15 @@ class SomeComponent extends Component {
}
```
In a hook, the `Component.current` static property is the reference to the
component instance that is currently being created. Hooks need to be called in
the constructor to ensure that this reference is properly set.
As you can see, the `useState` hook does not need to be given a reference to
the component. This is possible because there is a way to get a reference to the
current component: the `Component.current` static property is the reference to the
component instance that is currently being created.
Hooks need to be called in the constructor to ensure that this reference is
properly set. This is also a good thing for performance reasons (Owl can use
this to optimize its implementation), and for a clean architecture (this makes
it easier for developers to understand what is really happening in a component).
### `useState`