useThrottledMemo
useThrottledMemo<
T>(seconds,factory,initialValue,identifier?):T
Defined in: src/std/hooks/useThrottledMemo.ts:24
Memoizes a value, updating it at most once every seconds.
Returns the memoized value, which is initialized with initialValue and updated by factory when the throttle allows.
An optional identifier can be provided to create separate throttle states for different usages.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”seconds
Section titled “seconds”number
factory
Section titled “factory”() => T
initialValue
Section titled “initialValue”T
identifier?
Section titled “identifier?”unknown
Returns
Section titled “Returns”T
Example
Section titled “Example”function drawRandomValue() { // Updates a random value every 0.5 seconds. // When 0.5 seconds have not yet passed, the previous value is returned instead, preventing UI flicker. const value = useThrottledMemo(0.5, () => math.random(), 0) // Draws at 60 FPS, but the value only updates every 0.5 seconds. label.Text = `Value: ${value}`}