How to use the vtex.render-runtime.useRuntime function in vtex

To help you get started, weā€™ve selected a few vtex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vtex-apps / store / react / components / NetworkStatusToast.js View on Github external
function NetworkStatusToast({ intl }) {
  const runtime = useRuntime()
  const [offline, setOffline] = useState(false)
  // Useful to dismissable toast flow.
  const [showingOffline, setShowingOffline] = useState(false)
  const { showToast, hideToast, toastState } = useContext(ToastContext)

  const toastConfig = useMemo(
    () => ({
      message: intl.formatMessage({
        id: 'store/store.network-status.offline',
      }),
      dismissable: pathOr(false, ['hints', 'mobile'], runtime),
      duration: Infinity,
    }),
    [intl, runtime]
  )
github vtex-apps / store / react / ProductContext.js View on Github external
function useNotFound(loading, propsProduct, slug) {
  const { navigate } = useRuntime()

  useEffect(() => {
    if (!propsProduct && !loading) {
      navigate({
        page: 'store.search',
        params: { term: slug },
        query: `productLinkNotFound=${slug}`,
      })
    }
  }, [loading, propsProduct, navigate, slug])
}
github vtex-apps / store / react / components / ProductTitleAndPixel.tsx View on Github external
function usePageInfo(titleTag: string, product: MaybeProduct, selectedItem: SKU, loading: boolean) {
  const { account } = useRuntime()
  const { productName = undefined } = product || {}

  const pageEvents = useMemo(() => {
    const { brand = undefined, categoryId = undefined, categoryTree = undefined, productId = undefined } = product || {}

    if (!product || typeof document === 'undefined' || !selectedItem) {
      return []
    }

    const hasCategoryTree = categoryTree && categoryTree.length

    const pageInfo: any = {
      event: 'pageInfo',
      eventType: 'productView',
      accountName: account,
      pageCategory: 'Product',
github vtex-apps / store / react / components / ProductTitleAndPixel.tsx View on Github external
function useTitle(product: Product) {
  const { getSettings } = useRuntime()
  const { titleTag = undefined, productName = undefined } = product || {}
  let title = titleTag || productName || ''

  const settings = getSettings(STORE_APP)

  if (settings) {
    const { storeName, titleTag: storeTitleTag } = settings
    const storeData = storeName || storeTitleTag
    if (storeData) {
      title += title ? titleSeparator + storeData : storeData
    }
  }

  return title
}
github vtex-apps / store / react / ProductContext.js View on Github external
function useNotFound(loading, propsProduct, slug) {
  const { navigate } = useRuntime()

  useEffect(() => {
    if (!propsProduct && !loading) {
      navigate({
        page: 'store.search',
        params: { term: slug },
        query: `productLinkNotFound=${slug}`,
      })
    }
  }, [loading, propsProduct, navigate, slug])
}
github vtex-apps / store / react / components / StructuredData.js View on Github external
function StructuredData({ product, selectedItem }) {
  const {
    culture: { currency, locale },
  } = useRuntime()
  const productLD = parseToJsonLD(product, selectedItem, currency, locale)

  return (