PricingBlog

repeatedly using return values from an api call

  • rscott-1208182117448683641

    Bishop

    1 year ago

    If I reference the return value of /auth/me/data/user_id repeatedly, does it repeatedly call the api? I would expect it to NOT call the API repeatedly. But what I'm seeing is if I refer to that full path (/auth/me/data/user_id) instead of assigning to a variable and then using the variable, /auth/me/data/user_id at some point goes to null.

    The solution is to assign it to a variable first and use the variable in the repeat. But this was not expected and I would like some confirmation of best practice around this.

    I think assigning it to a variable first is a wasted step. And bringing down user_id from /auth/me once and repeatedly referring to it as if its a normal variable seems like it should work. But in reality it seems not to, and its super inconsistent.
  • andreasmoller-1208190692518527007

    Andreas Møller

    1 year ago

    Hey. No APIs should not refetch when you access their data. only when the data they are dependent on changes.
  • rscott-1208220026960613466

    Bishop

    1 year ago

    Hmm well it seems like I fixed my issue by not accessing the /auth/me/data/user_id variable repeatedly. It was definitely going to null when used in a repeat. 😦
  • andreasmoller-1209079677625569390

    Andreas Møller

    1 year ago

    Ill do some testing and see if I can reproduce.

    If you find the steps to reproduce, or it happens again please let me know.