Every line of 'settimeout react native' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
370 setTimeout (fn, time = 0, state = TimerState.CLEAR) { 371 this.clearTimeout(); 372 if (window) { 373 this.timerState = state; 374 this.timer = window.setTimeout(() => { 375 this.timerState = TimerState.CLEAR; 376 fn(); 377 }, time); 378 } 379 }
15 function withTimer( 16 WrappedComponent: React.ComponentType, 17 intervalInMs: number = 60 * 1000, 18 ): React.ComponentType> { 19 return class extends React.Component, TimerData> { 20 intervalId?: number; 21 22 static displayName = wrapComponentName(WrappedComponent, withTimer.name); 23 24 state: TimerData = { 25 currentTime: getCurrentTime(), 26 }; 27 28 componentDidMount() { 29 this.intervalId = window.setInterval( 30 () => this.setState({ currentTime: getCurrentTime() }), 31 intervalInMs, 32 ); 33 document.addEventListener('visibilitychange', this.onPageVisibilityChange); 34 } 35 36 componentWillUnmount() { 37 clearInterval(this.intervalId); 38 document.removeEventListener('visibilitychange', this.onPageVisibilityChange); 39 } 40 41 onPageVisibilityChange = () => { 42 // Page visibility changes when tabs go in and out of focus. When tabs 43 // are out of focus, mobile browsers slow down timers, so we run an 44 // additional check to make sure the page state has not drifted too far 45 // from the wall clock 46 const now = getCurrentTime(); 47 if ( 48 !document.hidden && 49 differenceInMilliseconds(now, this.state.currentTime) > intervalInMs 50 ) { 51 this.setState({ currentTime: now }); 52 } 53 }; 54 55 render() { 56 // TODO: remove as Props hack as defined in: 57 // https://github.com/Microsoft/TypeScript/issues/28938#issuecomment-450636046 58 return ; 59 } 60 }; 61 }
85 export function useClearTimeout( timeout ) { 86 useEffect( () => { 87 return () => { 88 window.clearTimeout( timeout ); 89 }; 90 }, [ timeout ] ); 91 }
30 componentDidMount() { 31 this.props.clearTimeout(this.timeoutId) 32 this.timeoutId = this.props.setTimeout(() => { 33 this.setState({ 34 showFeedback: true, 35 }) 36 }, 4000) 37 }
6 export function useTimeout( 7 callback: () => any, 8 delay: number | null, 9 memo?: any[] 10 ): void { 11 const savedCallback: React.MutableRefObject<(() => any) | undefined> = useRef(); 12 13 useEffect( 14 () => { 15 savedCallback.current = callback; 16 }, 17 [callback, Array.isArray(memo) ? memo : ""] 18 ); 19 20 useEffect( 21 () => { 22 function tick(): void { 23 if (isFunction(savedCallback.current)) { 24 savedCallback.current(); 25 } 26 } 27 28 if (delay !== null) { 29 const id: number = window.setTimeout(tick, delay); 30 return (): void => window.clearTimeout(id); 31 } 32 }, 33 [delay, Array.isArray(memo) ? memo : ""] 34 ); 35 }
33 public constructor(options?: ReactNativeOptions) { 34 this._options = { 35 onerror: true, 36 onunhandledrejection: true, 37 ...options 38 }; 39 }
13 public SetTimeoutExample():number { 14 var intervalId: number = egret.setTimeout(this.myDelayedFunction,this, this.delay, ["Hello", "World"]); 15 return intervalId; 16 }
17 componentDidMount() { 18 if (this.props.enabled) { 19 this.start(); 20 } 21 }
22 patchReactNativeWithZone(zone: any): void {}
9 export default function useTimeout(callback, delay) { 10 const savedCallback = useRef() 11 12 // Remember the latest callback. 13 useEffect(() => { 14 savedCallback.current = callback 15 }, [callback]) 16 17 // Set up the timeout. 18 useEffect(() => { 19 const tick = () => { 20 savedCallback.current() 21 } 22 if (delay !== null) { 23 const id = setTimeout(tick, delay) 24 return () => clearTimeout(id) 25 } 26 return undefined 27 }, [delay]) 28 }