pmndrs / drei

🥉 useful helpers for react-three-fiber
https://drei.pmnd.rs/
MIT License
7.83k stars 642 forks source link

The onChange() function of the <Select/> component desynchronizes with the active state. #1980

Open cincolunes opened 4 weeks ago

cincolunes commented 4 weeks ago

Problem description:

The onChange() function of the Select component currently returns the previous value of the active state when multiple items are selected, and nothing when a single item is selected, due to the downed state interrupting its execution.

Relevant code:

  React.useEffect(() => {
    if (downed) onChange?.(active)
    else onChangePointerUp?.(active)
  }, [active, downed])

Suggested solution:

  React.useEffect(() => {
    if (!downed) onChange?.(active)
    else onChangePointerUp?.(active)
  }, [active, downed])

I'm going to provide a PR with this one.