Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$onUpdated Hook not functioning on imported component #4272

Open
travelsetu opened this issue May 18, 2024 · 0 comments
Open

$onUpdated Hook not functioning on imported component #4272

travelsetu opened this issue May 18, 2024 · 0 comments

Comments

@travelsetu
Copy link

travelsetu commented May 18, 2024

I've encountered a problem with lifecycle hooks. Specifically, when I import a component, the $onUpdated hook doesn't seem to function properly when the props are updated in the main component.

Expected Behaviour
Retrieve the updated data on the $onUpdated hook of the Subcomponent when data is updated in the main component.

Actual Behaviour
No data is received

Please check:

app.js

...
import chart from "../components/chart.f7"
Framework7.registerComponent(
  'x-chart', chart
)
...

Main Chart Component

<template>
  <div class="page" data-name="charts">
    <div class="navbar">
      <div class="navbar-bg"></div>
      <div class="navbar-inner">
        <div class="left">
          <a href="#" class="link back">
            <i class="icon icon-back"></i>
          </a>
        </div>
        <div class="title">About</div>
      </div>
    </div>
    <div class="page-content">
      <div class="block-title">Charts</div>
      <div class="block">
        <x-chart data-title="Monthly Sales" data-chartdata="${chartdata}"></x-chart>
      </div>
    </div>
  </div>
</template>
<script>
  export default (props, { $on, $update }) => {
    let chartdata = [1, 2, 3]
    $on('pageInit', function () {
      setTimeout(function () {
        chartdata = [3, 4, 5]
        $update()
      }, 2000)
    })
    return $render;
  };
</script>

Subcomponent: components/chart.f7"

<template>
    <div>
        <div>${props.dataTitle}</div>
        <canvas></canvas>
    </div>
</template>
<script>
    export default (props, { $on, $onUpdated }) => {
        console.log(props)
        $onUpdated(function () {
            console.log(props)
        })
        return $render;
    };
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant