Tengo algunos botones de segmentos iónicos que esencialmente actúan como interruptores de palanca. Estoy tratando de limitar la velocidad a la que se pueden cambiar/seleccionar los efectos de los conmutadores) y probé Debounce & Throttle desde ambos lodash y ahora subraya sin éxito.
Actualmente estoy usando guiones bajos y todavía tengo el problema de que la función todavía se llama libremente a pesar del uso de rebote.
Aquí está mi código:
<IonSegment onIonChange={e => setOptionsHandlerThrottled(e.detail.value as string, "Trigger", "statusSensorHighTrigger")} className="lowercase" color="brand" value={settingsHandler("statusSensorHighTrigger")}> <IonSegmentButton value="false"> <IonLabel>Low</IonLabel> </IonSegmentButton> <IonSegmentButton value="true"> <IonLabel>High</IonLabel> </IonSegmentButton> </IonSegment> const setOptionsHandler = (value: string, option: string, key: string) => { if (value === "true") { console.log("RESULT: True / " + value + " / " + option + " / " + key); if (!settingsHandler(key)) { setControlHandler(option, false); //toggle on console.log("TOGGLE " + option + " ON!"); } } else { // false console.log("RESULT: False / " + value + " / " + option + " / " + key); if (settingsHandler(key)) { setControlHandler(option, false); //toggle off console.log("TOGGLE " + option + " OFF!"); } } } const setOptionsHandlerThrottled = _.debounce(setOptionsHandler, 5000, true); ¿Por qué se sigue llamando a setOptionsHandler cuando IonSegmentButton cambia independientemente del tiempo de espera de rebote? ¿Estoy creando accidentalmente una nueva función rebotada cada vez que se llama?