Coding-Dodo/owl-realworld-app

Re-render current component

Closed this issue · 2 comments

Hi, i'm trying to learn OWL but i got a question. How to re-render current component? For example, article navigation sidebar inside ArticlePage. If I add a reference to the current component inside this component, then a full rerender does not happen. It still call render function, but without willStart.
You can repeat this by adding <Link to="'ARTICLE'" params="{slug: 'grupo-primo-n07nv4'}" ><t t-esc="'grupo-primo-n07nv4'" /></Link> inside ArticlePage or App component. Then open an article other than "grupo-primo-n07nv4" and click on link.
Expected result: fetching new data and re-render ArticlePage component.
But only url hash changed.

Have any ideas how to do this?

Hello @blast71 and thank you for your interest.

I've merged a new PR correcting your issue.

I am sorry, in the tutorial, I didn't really show any good example of the onWillUpdateProps hook. But this is what you would use in this case.

Inside the new props provided by that hook, you will have the new slug "Grupo-primo-n07nv4" and can do a new API
fetch from that that you assign to your article state, the component will re-render following that change.

onWillUpdateProps(async (nextProps) => {
    if (nextProps.slug !== undefined) {
        await fetchArticle(nextProps.slug);
    }
});

Thank you!