Actions
Last updated
import { ShopstoryProvider } from "@shopstory/core/react";
import { CustomComponent } from "../components/CustomComponent/CustomComponent";
const AlertAction = (props: { text: string }) => {
alert("Alert message: " + props.text);
}
export const DemoShopstoryProvider : React.FC = ({ children }) => {
return <ShopstoryProvider
actions={{
AlertAction
}}
>
{ children }
</ShopstoryProvider>
}export const DemoShopstoryProvider : React.FC = ({ children }) => {
const myContext = useContext(MyContext) // Running a React hook
return <ShopstoryProvider
actions={{
CustomAction: () => {
// accessing hook data in the action code
alert("Value from useContext hook: " + myContext.valueFromContext);
}
}}
>
{ children }
</ShopstoryProvider>
}