@1productaweek/react-wait-for-window 中文文档教程

发布于 4年前 浏览 16 项目主页 更新于 3年前

React Wait for Window

等待窗口道具可用。 例如,如果您正在加载 Stripe async,您将需要等待它变得可用,然后再尝试使用任何依赖它的组件。

npm install @1producataweek/react-wait-for-window

useWaitForWindow(prop: string, timer: number): boolean

当 window 道具可用时将更新的挂钩。 根据是否在 window 上设置 prop 返回 true/false。 计时器是应该检查 prop 的时间间隔。

import { useWaitForWindow } from '@1producataweek/react-wait-for-window'

function Component () {
  const propIsAvailable = useWaitForWindow('stripe', 1000)

  if (!propIsAvailable) return 'Loading'

  return <ComponentThatDependsOnWindowProp />
}

WaitForWindow

当 window 道具可用时将更新的挂钩。 根据是否在 window 上设置 prop 返回 true/false。 计时器将设置

import&nbsp;{ WaitForWindow } from '@1producataweek/react-wait-for-window'

function Component () {
  return (
    <WaitForWindow prop='' timer={1000}>
      <ComponentThatDependsOnWindowProp />
    </WaitForWindow>
  )
}

Made by 1PAW

https://1productaweek.com | |- Ralley - 队列服务 |- Snapboard - 简单的可破解仪表板

React Wait for Window

Waits for a window prop to become available. E.g. if you're loading Stripe async, you will need to wait for it to become available before trying to use any components that rely on it.

npm install @1producataweek/react-wait-for-window

useWaitForWindow(prop: string, timer: number): boolean

A hook that will update when the window prop becomes available. Returns true/false depending on whether the prop is set on window. The timer is the interval that the prop should be checked.

import&nbsp;{ useWaitForWindow } from '@1producataweek/react-wait-for-window'

function Component () {
  const propIsAvailable = useWaitForWindow('stripe', 1000)

  if (!propIsAvailable) return 'Loading'

  return <ComponentThatDependsOnWindowProp />
}

WaitForWindow

A hook that will update when the window prop becomes available. Returns true/false depending on whether the prop is set on window. The timer will set

import&nbsp;{ WaitForWindow } from '@1producataweek/react-wait-for-window'

function Component () {
  return (
    <WaitForWindow prop='' timer={1000}>
      <ComponentThatDependsOnWindowProp />
    </WaitForWindow>
  )
}

Made by 1PAW

https://1productaweek.com | |- Ralley - queue as a service |- Snapboard - simple hackable dashboard

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文