# Load Data only the first time you enter a page

**URL:** <https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682>\
**Category:** How-to Discussions\
**Created:** [March 31, 2016, 5:48pm UTC](https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682 "2016-03-31T17:48:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nico.ronconi](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@nico.ronconi](https://forums.fusetools.com/u/nico.ronconi)\
**Post date:** [March 31, 2016, 5:48pm UTC](https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682/1 "2016-03-31T17:48:15Z")

</div>

Hi guys,

in the forum i didn’t find this How-to so i am here to ask this.

Is there a way to fetch some data only the first time u enter in a specific page?

I have a linear navigation and i want to fetch some data when i swipe in the second page but only the first time. If a user swipe back (in page 1) and again swipe in page 2, the page 2 will not fetch again the data.

Hope someone can help 🙂

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [April 1, 2016, 1:48am UTC](https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682/2 "2016-04-01T01:48:18Z")

</div>

Not sure if you’re using `PageControl` but doesn’t really matter what your using for your page, as long as you use `WhileActive` like so in the following **simplified** example:

```auto
<PageControl>
  <Page></Page>
  <Page>
    <WhileActive>
      <Callback Handler="{loadData}" />
    </WhileActive>
  </Page>
</PageControl>

```

```auto
var isDataLoaded = Observable(false);

function loadData() {
  if(!isDataLoaded) {
    fetch(url).then(function(res) {...}).then(data) {
     // do stuff with your data
     isDataLoaded.value = true; // set the isDataLoaded to true so that it won't load the data again
    });
  }
}

module.exports = {
  loadData: loadData
}

```

You could also check the `isDataLoaded` boolean through ux:

```auto
<PageControl>
  <Page></Page>
  <Page>
    <WhileActive>
      <WhileFalse Value="{isDataLoaded}>
        <Callback Handler="{loadData}" />
      </WhileFalse>
    </WhileActive>
  </Page>
</PageControl>

```

```auto
var isDataLoaded = Observable(false);

function loadData() {
  fetch(url).then(function(res) {...}).then(data) {
    // do stuff with your data
    isDataLoaded.value = true; // set the dataLoaded to true so that it won't load the data again
  });
}

module.exports = {
  isDataLoaded: isDataLoaded,
  loadData: loadData
}

```

---

<div class="post-metadata">

**Author:** ![nico.ronconi](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@nico.ronconi](https://forums.fusetools.com/u/nico.ronconi)\
**Post date:** [April 6, 2016, 7:51pm UTC](https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682/3 "2016-04-06T19:51:08Z")

</div>

hi edwin.

Yes this is exactly what i did. But is there a trigger to do that instead of define a boolean variable?

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [April 7, 2016, 5:21am UTC](https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682/4 "2016-04-07T05:21:28Z")

</div>

Nope, not that I know of

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [April 12, 2016, 2:59pm UTC](https://forums.fusetools.com/t/load-data-only-the-first-time-you-enter-a-page/6682/5 "2016-04-12T14:59:47Z")

</div>

There is no trigger which only triggeres the first time an event is called. Since this case is quite specifig i think the approach you’ve used is a good one. If you absolutely want to keep this logic inside UX (which i don’t think is a good practice anyway), then you could do it by wrapping the callback in a `WhileTrue`.

Something like this:

```auto
<WhileTrue ux:Value="activateOnce">
    <Callback Handler="{loadData}" />
</WhileTrue>

...

<Page>
    <WhileActive>
        <Set activateOnce.Value="true" />
    </WhileActive>
</Page>

```
