Hello, Plasmic Team is there a way to declare global actions that would be accessible through interactions menu? I’ve found that Global Context
has unstable__globalActions
property for adding custom global actions but I can’t make it to work (I see my registered global action inside interactions menu, but it does nothing) Example in the comment
plasmic-init.ts
PLASMIC.registerGlobalContext(GlobalContext, {
name: 'GlobalContext',
displayName: 'Global Context',
props: {},
unstable__globalActions: {
submitQuizAnswer: {
displayName: 'Submit quiz answer',
parameters: [
{
name: 'question',
displayName: 'Question Key',
type: 'string',
},
{
name: 'answer',
displayName: 'Answer',
type: 'string',
},
],
},
},
});
GlobalContext.tsx
export const GlobalContext = forwardRef<
GlobalContextActions,
GlobalContextProps
>(function GlobalContext(props, ref) {
const { children } = props;
useImperativeHandle(
ref,
() => ({
submitQuizAnswer: (question, answer) => {
console.log({ question, answer });
},
}),
[],
);
return <>{children}</>;
});
or
export const GlobalContext = (props: GlobalContextProps) => {
const { children } = props;
const contextValue: ContextType = useMemo(
() => ({
submitQuizAnswer: (question, answer) => {
console.log({ question, answer });
},
}),
[],
);
return (
<Context.Provider value={contextValue}>
{children}
</GlobalContext.Provider>
);
};
I’ve tried similar approach like we have for defining Element Actions
but I’m not sure
Hey @flawless_capybara! The global actions are currently in an experimental phase. We will be releasing them officially this week and will be removing the unstable
prefix.
However, there will be some small changes in the registration process.
If you would still like to test it before the official release, I can help you via DM
thanks, Samuel, for letting me know no rush from my side, I can wait for the official release