interval / interval-node

The official Interval SDK for Node.
https://interval.com/docs
121 stars 13 forks source link

Page's handler called many time after render #22

Open alejo-acevedo-deel opened 1 year ago

alejo-acevedo-deel commented 1 year ago

I am using a Page component to show a table, into the handler of the Page I am calling a function to query a DB and this function is called many times ramdomly which could be a bit problematic

Example:

export default new Page({
  name: 'Users',
  handler: async () => {
    const data = await getAllUsers()

    return new Layout({
    .
    .
    .

getAllUsers() is being called many times

Solution

Handler should be executed only once at the moment of render the page, or even better it would be nice have a way to control it. At least it would be necessary have a some explanation on the documentation when and why the handler function is executed.

danphilibin commented 1 year ago

Hi - which version of our SDK are you using? And are you seeing this in the Development or Production environment?

jacobmischka commented 1 year ago

Sorry, what do you mean by "randomly"? Is any navigation happening? Is the page just sitting idle?

alejo-acevedo-deel commented 1 year ago

Hi - which version of our SDK are you using? And are you seeing this in the Development or Production environment?

I am using "@interval/sdk": "^0.36.0" at development enviroment

alejo-acevedo-deel commented 1 year ago

Sorry, what do you mean by "randomly"? Is any navigation happening? Is the page just sitting idle?

When you recharge the page, the getAllUsers method is called many time when with just one call would be enough