Hooks in Odoo OWL Framework

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

17/06/2021 Hooks in Odoo OWL Framework

Enable Dark Mode!

By:Mashood K
AUG 5,2020

Hooks in Odoo OWL Framework


Technical Odoo 13

The owl is a framework from Odoo to meet Odoo’s front end requirements. We have talked about it in
the previous section about Odoo OWL Framework. Today, we are going to take a look at what are
hooks in the OWL framework and how do we use it.

Hooks are used to reusing stateful logic between components. Hooks are always observed with the
Observer class to keep track of what is going on in states and react to their changes.

There are some common hooks used by OWL.

1. useState Hook

2. onMounted

3. onWillUnMount

4. onWillPatch

5. onPatched

6. onWillStart
Home Odoo Implementation Customization Training Support Resources B

7. onWillUpdateProps

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 1/9
17/06/2021 Hooks in Odoo OWL Framework

Let's see each hook in detail

1. useState Hook
useState is one of the most important and common hooks in the owl framework. It has a major role in
the feature ‘reactive framework’. This hook helps to render a view when a state of a component is
changed. This makes the Owl framework ‘reactive’ as it always listens to the changes occurring in the
states of a component.

const { useState } = owl.hooks;


class Counter extends owl.Component {
  static template = xml`
    <button t-on-click="increment">
        Click Me! [<t t-esc="state.value"/>]
    </button>`;
 state = useState({ value: 0 });
 increment() {
    this.state.value++;
 }
}

As you can see above, when the value of the state is changed from the function increment(), it
renders the template again with the help of useState. We don't want to re-render the template again
and again whenever the value of a state is changed. You can see that the state is defined as its value
using useState as an object. That is because UseState only accepts a value as an array or object.
Since it is the only possible way to react to a state change.

2. onMounted
onMounted hooks register a callback that is called when the owl component is mounted from the
virtual DOM to the UI representation(Simply component mounting). In other words, onMounted hook
calls when a component is represented in the view. 

3.onWillUnMount

onMounted hooks register a callback that is called when the owl component is unmounted from the
view.

4.onWillPatch
onMounted hooks register a callback that is called before the component is patched.

5.onPatched
onMounted hooks register a callback that is called after the component is patched.

6.onWillStart
This hook will be called just before the component is rendered for the first time. It will be useful if we
need to do some actions before the component is rendered to the view like loading some initial data.
Home Odoo Implementation Customization Training Support Resources B

7.onWillUpdateProps

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 2/9
17/06/2021 Hooks in Odoo OWL Framework

This is also an asynchronous hook which is called whenever an update is made to a related
component. The reactive nature of the OWL framework can be maintained using this amazing hook.

Watch our Odoo OWL Framework webinar to know more about Hooks in Odoo OWL

Odoo 14 Webinar - Odoo Owl Framework

If you need any assistance in odoo, we are online, please chat with us.

Whatsapp Chat Now

Share this article:

« Previous
Next »

Related Blogs
Prerequisites On Monthly Payroll Management With Odoo
Home Odoo Implementation Customization Training Support Resources B
Prerequisites On Monthly Payroll Management With Odoo

Odoo Dignified Tools Will Help Your Company Stand Above The Curve In Productivity
https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 3/9
17/06/2021 Hooks in Odoo OWL Framework

Odoo Dignified Tools Will Help Your Company Stand Above The Curve In Productivity

Secondary Sales Operations with Odoo

Secondary Sales Operations with Odoo

Odoo ERP - Is It a Suitable Solution for Business in the US

Odoo ERP - Is It a Suitable Solution for Business in the US

How Can Distinctive Modules of ERP Add Up Your Company

How Can Distinctive Modules of ERP Add Up Your Company's Growth?

0
Comments

Leave a comment

Name

Email
Website
Comment

Post Comment

Now Available on Amazon

Home Odoo Implementation Customization Training Support Resources B

Odoo Technical Webinar

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 4/9
17/06/2021 Hooks in Odoo OWL Framework

Recent Posts

Prerequisites On Monthly Payroll Management With Odoo

Odoo Dignified Tools Will Help Your Company Stand Above The Curve In Productivity

Home Odoo Implementation Customization Training Support Resources B

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 5/9
17/06/2021 Hooks in Odoo OWL Framework

Secondary Sales Operations with Odoo

Odoo ERP - Is It a Suitable Solution for Business in the US

How Can Distinctive Modules of ERP Add Up Your Company's Growth?

CALICUT
Cybrosys Technologies Pvt. Ltd.

Neospace, Kinfra Techno Park

Kakkancherry, Calicut

Kerala, India - 673635 Home Odoo Implementation Customization Training Support Resources B

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 6/9
17/06/2021 Hooks in Odoo OWL Framework

LONDON
Cybrosys Limited

Alpha House,

100 Borough High Street, London,

SE1 1LB, United Kingdom

KOCHI
Cybrosys Technologies Pvt. Ltd.

1st Floor, Thapasya Building,

Infopark, Kakkanad,

Kochi, India - 682030.

BANGALORE
Cybrosys Techno Solutions

The Estate, 8th Floor,

Dickenson Road,

Bangalore, India - 560042

Home Odoo Implementation Customization Training Support Resources B


SEND US A MESSAGE

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 7/9
17/06/2021 Hooks in Odoo OWL Framework

Full Name

E-mail

Phone

Your Message

SEND

QUICK LINKS

Odoo

Odoo Apps

Odoo Partners

Buy Source code

Contact us

Sitemap

SERVICES

Odoo Customization

Hire Odoo Developer

Odoo Implementation

Odoo Integration

Odoo Support

Odoo Migration

Odoo Consultancy Home Odoo Implementation Customization Training Support Resources B

Odoo Training

Odoo Licensing
https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 8/9
17/06/2021 Hooks in Odoo OWL Framework

REFERENCE

Odoo ERP

Odoo Software

Odoo vs SAP

Odoo vs Dynamics
Odoo vs ERP Next

Odoo vs Netsuite

Odoo vs Sage

Odoo vs Sugar CRM

Odoo vs Zoho CRM

STAY IN TOUCH


+91 8606827707


info@cybrosys.com


+91 8606827707

CONNECT SOCIALLY

Copyright 2021 Cybrosys Technologies. All






Rights
Reserved. Privacy Policy

https://www.cybrosys.com/blog/hooks-in-odoo-owl-framework 9/9

You might also like