leva icon indicating copy to clipboard operation
leva copied to clipboard

Hey @Sean-Bradley, a few observations:

Open RonBonBon opened this issue 1 year ago • 1 comments

Hey @Sean-Bradley, a few observations:

  • what's the problem with buttons being recreated on each render? Is there some scaling issue that I'm not aware of?
  • there's no problem with bypassing the exhaustive-deps lint rule in general, as long as you know what you're doing. We actually do that a lot in Leva 🤧

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

RonBonBon avatar May 27 '24 04:05 RonBonBon

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.

Sean-Bradley avatar May 27 '24 07:05 Sean-Bradley