RikiBorders / Rift-Watcher

Data-Driven League of Legend's Statistics Website
https://rift-watcher.vercel.app
1 stars 0 forks source link

bug with items not adding in build calculator #17

Closed RikiBorders closed 1 year ago

RikiBorders commented 1 year ago

adding items works fine from the searchbar, but not from the new carousel.

I tried moving the carousel code directly into the build calculator parent component, but that didn't work. Should be an issue with add or delete functions either since the search bar method works for adding items.

RikiBorders commented 1 year ago

by using my brain i dont think the issue is adding/deleting, since the searchbar works for adding items

RikiBorders commented 1 year ago

Found a good lead: https://stackoverflow.com/questions/46294988/how-to-add-components-to-list-dynamically-in-react-with-no-redundant-render

Looks like I should the divs with classname 'carousel_list_view' in the load_item_lists function into their own components, while giving them unique key values. May need to take this a step further and do the same for the render_item_table functions if the aformentioned solution doesnt work.

RikiBorders commented 1 year ago

Actually the above solution seems unrelated. may need to keep searching. this is the google queyr I most recently used:

react rendering from list resets

RikiBorders commented 1 year ago

Couldn't stop thinking about the problem and found the start of the solution:

I added useRef and created a reference to the build, to get the most up-to-date *mutable version of the state in whatever callback needs the updated state. This fixes the inability to update the build with items from the item lists, however useref doesn't trigger re-renders, which needs to be fixed

article:

https://stackoverflow.com/questions/57847594/react-hooks-accessing-up-to-date-state-from-within-a-callback

RikiBorders commented 1 year ago

re-added shallow copy for build after items are added (set state doesnt re-render redundant array references).