sleep in react 1

sleep in react

    sleep = (milliseconds) => {
        return new Promise(resolve => setTimeout(resolve, milliseconds))
    }
	
    componentDidUpdate(prevProps, prevState, snapshot) {
            this.sleep(5000).then(r => {
            // do something
      	    })
    }

Here is what the above code is Doing:
1. We’re using the componentDidUpdate lifecycle method to run some code after the component has updated.
2. We’re using the sleep function to wait for 5 seconds.
3. We’re using the setState method to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is called after the component has updated.

The sleep function is used to wait for 5 seconds.

The setState method is used to update the state of the component.

The componentDidUpdate lifecycle method is

Similar Posts