[IMP] components: add hooks mechanism

part of #194
This commit is contained in:
Géry Debongnie
2019-09-24 14:06:53 +02:00
parent 4513e3f31c
commit 5335fb8fba
28 changed files with 781 additions and 358 deletions
+4 -1
View File
@@ -20,6 +20,7 @@ Here is a short example to illustrate interactive components:
```javascript
import { Component, QWeb } from 'owl'
import { xml } from 'owl/tags'
import { useState } from 'owl/hooks'
class Counter extends Component {
static template = xml`
@@ -27,7 +28,7 @@ class Counter extends Component {
Click Me! [<t t-esc="state.value"/>]
</button>`;
state = { value: 0 };
state = useState({ value: 0 });
increment() {
this.state.value++;
@@ -48,6 +49,8 @@ const app = new App({ qweb: new QWeb() });
app.mount(document.body);
```
Note that the counter component is made reactive with the `useState` hook.
More interesting examples can be found on the
[playground](https://odoo.github.io/owl/playground) application.