@1productaweek/react-wait-for-window 中文文档教程
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 { 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 { 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 { 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