genshin-optimizer
genshin-optimizer copied to clipboard
Tally should update on add/remove, not all events
This is more of a nit to how we do this in GO, I think these gets rerendered every time we change an artifact/relic, but it should rerender every time an artifact/relic is added/removed (since it only display the total).
It make sense to use the DataManagerCallback.reason
string, and check against 'remove' | 'new'
. Would also make sense to store total
as a state instead of useForceUpdate
, so when total is set as the same value again, it doesnt trigger a revalue.
Originally posted by @frzyc in https://github.com/frzyc/genshin-optimizer/pull/2025#discussion_r1582361651
Psudocode:
const [tally, setTally] = useState(database.relics.length)
useEffect(()=>databse.relics.followAny((_,reason)=>['remove','new'].includes(reason) && setTally(database.relics.length),[database])
Example implementation https://github.com/frzyc/genshin-optimizer/pull/2061
@frzyc I'm happy to look at this for you if that's ok?
Thanks, let me know if you have any questions