I have a code component in my global PageLayout component that exposes element actions and some data in $ctx
I’m successfully able to:
• Use the data within the PageLayout component
• Use the element actions within the PageLayout component
• Use the data in the pages that use PageLayout (ie “children” slot)
However, I can’t seem to access the element actions in the pages that use PageLayout (ie its children) (even though I can access it’s data in there).
Is this expected behaviour? Any way around it?
@jason this relates to what we were talking about earlier (see thread)
Note that I first tried using AuthProvider as a global context, but typescript said that refActions was not available (ie element actions were not allowed in a global context)
However, I can’t seem to access the element actions in the pages that use PageLayout (ie its children) (even though I can access it’s data in there).
You’re correct that element actions in a component can’t be called by consumers of the component. They can only be used internally right now (unlike DataProvider). We’ll look into the possibility of allowing them to be used by consumers.
Here are a few workarounds for this:
Use global context with global actions as mentioned by Victor
Expose actions as functions in the DataProvider, like:
Now when you add an interaction, use “Run code” and type in $ctx.auth.login(). It’s a bit more code instead of clicking, but the actions will properly flow.
3. Change ParentLayout to a code component and expose AuthProvider functions as element actions on the code component as usual.
I ended up using Global Context, and exposing functions in the DataProvider of the Global context.
I tried global actions and couldn’t get them to work
Hey Callum, sorry you had trouble setting up the global context. That’s partially our fault since we didn’t have the docs updated. I just took the time to update these docs in case you try again!