REACT - sharing data between siblings causes main app to re-render

31 views Asked by At

First of all, I'm learning react and never post anything here. Sorry if I sound confusing, cuz I really am...

I have the following project using Functional Components:

APP(Parent)
    |---- Header (child)
            |---- Favorites (grandchild - shows total of favorites)
  
    |---- ListGames (child)
            |---- Card
                    |----ButtonSendFavorites (grandchild)
  
    |---- Fotter (child)

These components are individual files. I used useState/Lifting State Up to send the selected game from my ListGames to Favorites(grandchild). Worked as intend, also as not intend, all my app re-renders. Took me few minutes to realise what happened (lifting state up to parent and changing it will cause a re-render, duhhhh). So... is there a way to send the selected game to Favorites (grandChild) without re-render APP and all of his children?

I tried useCallBack but as I said, I'm learning and in that point everything started to mix up. I even asked help to chatGPT but it's answer doesn't worked as well. So, is there a way to do it without advanced state management?! I hope that I made myself clear. Thanks anyways.

0

There are 0 answers