Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm stumbling over
Error: Function called outside component initialization
a lot recently when using the$session
store. And lack the understanding of where exactly this store actually can be used.The docs state "..must be accessed during component initialisation.." and "However, it still needs to be called synchronously on component or page initialisation when the $-prefix isn't used. Use getStores to safely .subscribe asynchronously instead."
So what does "component initialisation" phase actually mean? Searching the docs for that phrase does not yield anything. I was under the impression that
onMount
is part of that phase but I found that the session store can only be used in the template of a component and directly inside the<script>
block of a component. Everywhere else basically does not work, failing with the above mentioned error. Also usinggetStores
does not really work because as soon as I access the store viasession.subscribe()
orget()
it errors out with above error again.I want to use the information from the session store in the function of a non-component file. Is there any way I can achieve that?
Beta Was this translation helpful? Give feedback.
All reactions