Skip to main content
Version: Next

Taro.nextTick(callback)

Defers some operations until the next time slice. (similar to setTimeout)

Note

The APIs such as setData and triggerEvent in the custom component perform synchronous operations. When these APIs are continuously called, they are executed in a synchronous process, so if the logic is improper, an error may occur.

For example, when the parent component's setData triggers the triggerEvent of the child component, and the parent component performs setData again, during which the child component is unloaded via the wx:if statement, an error may occur. So for logic that does not need to be done in a synchronous process, you can use this API to defer some operations until the next time slice.

Reference

Type

(callback: (...args: any[]) => any) => void

Parameters

PropertyType
callback(...args: any[]) => any

Sample Code

this.setData({ number: 1 }) // Executes directly in the current synchronous process.
Taro.nextTick(() => {
this.setData({ number: 3 }) // After the current synchronous process ends, execute the operations in the next time slice.
})
this.setData({ number: 2 }) // Executes directly in the current synchronous process.

API Support

APIWeChat Mini-ProgramH5React Native
Taro.nextTick✔️