pmndrs / leva

🌋 React-first components GUI
https://leva.pmnd.rs
MIT License
4.8k stars 195 forks source link

Hey @Sean-Bradley, a few observations: #502

Open RonBonBon opened 2 months ago

RonBonBon commented 2 months ago

Hey @Sean-Bradley, a few observations:

However, here the solution to your problem is pretty obvious:

 const buttons = useMemo(() => {
     const _buttons = {}
    positions.forEach((p, i) => {
      _buttons['button ' + i] = button(() => setTo(p))
    })
   return _buttons
  }, [positions, setTo])

And if you're a fan of the reduce function:

 const buttons = useMemo(() => positions.reduce((acc, p, i) =>
  Object.assign(acc, { [`button ${i}`]: button(() => setTo(p)) }), {}), [positions, setTo])

Originally posted by @dbismut in https://github.com/pmndrs/leva/discussions/393#discussioncomment-3881633

Sean-Bradley commented 2 months ago

It seems you have created a new issue from an issue that was already solved and closed. https://github.com/pmndrs/leva/discussions/393#discussioncomment-3881633

Your problem is unclear because this is a verbatim copy of just one of the comments from the original thread.