79812938

Date: 2025-11-08 02:50:56
Score: 0.5
Natty:
Report link

How about instead of creating new independent pieces of state and managing the dependence, you just define your rMin and rMax based on these (i.e. as "derived state")?

const [thresholdMin, setThresholdMin] =  useState<number>()
const [thresholdMax, setThresholdMax] =  useState<number>()

const rangeMin: Range[] = Array.from({length: thresholdMax-1}, (_, i) => ({
    label: v.value.toString() + " " +data.settings.sensor_unit,
    value: i + 1,
    }
));

const rangeMax: Range[] = Array.from({length: 10-thresholdMin}, (, i) => ({
    label: v.value.toString() + " " +data.settings.sensor_unit,
    value: i + thresholdMin + 1,
}));

Now these will automatically stay updated whenever thresholdMin and thresholdMax change

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How
  • Low reputation (0.5):
Posted by: TY Mathers