odoo/owl

t-ref is no longer supported on components. Consider exposing only the public part of the component's API through a callback prop.

pumppi opened this issue · 3 comments

Hi,

I want to access to component from template.
How to do that.

<BaseField t-ref="text" type="'text'" label="'text'" />

This t-ref isn't supported but theres now any examples how to implement callback pro.
My goal is to access component from the parent component to get values. For example field values.
Now I need to do props drilling if want to access for example onchange listener.

Looks like the solution is for example this kind of?

<BaseField componentMounted="(component) => this.setComponent(component)" />

The reason component ref were removed is because it's generally a bad idea to give unrestricted access to a component from outside: owl manages the lifecycle and lifetimes of component and passing component instances around is a bad idea and prone to leaking memory or operating on unmounted components. It's pretty easy to devise something similar to what's done in the React ecosystem: an imperative handle, where a component can opt into exposing a specific subset of its own API. Here is a link to such an implementation on the owl playground.

Thanks