genshin-optimizer icon indicating copy to clipboard operation
genshin-optimizer copied to clipboard

Tally should update on add/remove, not all events

Open frzyc opened this issue 9 months ago • 2 comments

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 avatar Apr 30 '24 07:04 frzyc

@frzyc I'm happy to look at this for you if that's ok?

AlexVascon avatar Apr 30 '24 08:04 AlexVascon

Thanks, let me know if you have any questions

frzyc avatar Apr 30 '24 14:04 frzyc