[V14+] How do I only call an API once and put the ...
# package-development
w
Question: How do I only call an API once and put the value somewhere where the app can read from it? I want to do a request only once when the user logs in to an API & store the values (an array of strings) into something that I can use to lookup the values in a condition later on. As condition code runs a lot, I don't need or want it to ping the API every time the condition is run as that seems overkill for the situation. The values will be configuration stored in AppSettings, so they will not change often
Just not sure what to look at in the existing codebase or what terms/questions to ask in order to try and find an example. If anyone got any pointers be it V14 package devs or anyone from HQ please let me know
n
How about a global context, and push that data into an observable / UmbObjectState? We do this in a few DXP products, seems to do the trick
Fetch the data when the context is created, or do it explicitly in an entry point
j
I agree with Nathan, a global context is what you are looking for
And put a Promise in there if you only update it once. No need for any states.
w
Thanks both, will try it when I get to my desk shortly
r
Yup doing the same for my most important Webcomponent the licensing message 🙂
w
Thanks all - was having a real brain block yesterday
m
@Warren Buckley please keep these kind of questions coming! It brings clarity to things that that I haven’t been thinking about (learning a lot) and it encourage a “ask anything” mindset which I really like!
12 Views